Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display base64 images in a html email on Ios

I generate a html string who contains base64 images. When the MFMailComposeViewController open, I see the images in the generated email. When I send it and open it, the images are not displayed, there are just empty square.

My code

- (IBAction)actionShareByEmail:(id)sender {

    if([MFMailComposeViewController canSendMail])
    {
        MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
        picker.mailComposeDelegate = self;

        NSString* subject = @"Environments list with qrcode";
        [picker setSubject:subject];
        [picker setMessageBody:[manager getHtmlWithEnvironments:nil] isHTML:YES];
        [self presentViewController:picker animated:YES completion:nil];
    }
}

-(NSString*)getHtmlWithEnvironments:(NSArray*)envDictionnaries{
    NSMutableString* html = [[NSMutableString alloc]init];
    [html appendString: @"<html><body>"];

    for (NSDictionary *d in self.arEnvironments) {

        UIImage* qrcode = [QRCodeGenerator qrImageForString:[d objectForKey:@"env_name"] imageSize:200.0];//Works fine
        NSData *imageData = UIImagePNGRepresentation(qrcode);
        NSString *encodedString = [imageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
        [html appendString: [NSString stringWithFormat:@"<H3>%@</h3><img src=\"data:image/png;base64,%@\" width=\"200\" height=\"200\" alt=\"test\" /></br></br>",[d objectForKey:KEY_ENV_NAME],encodedString]];
    }
    [html appendString: @"</html><body>"];

    return html;
}

How can I do to display images correctly ?

like image 542
Anthony Avatar asked Oct 24 '14 08:10

Anthony


1 Answers

It looks like support for inline images is low - mainly due to security issues.

The link to Campaign Monitor in the second question below gives more information.

More Information:

  • Send a base64 image in HTML email
  • Base64 HTML embedded images not showing when mailed
like image 151
Ruskin Avatar answered Sep 28 '22 11:09

Ruskin