8

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 ?

Anthony
  • 2,801
  • 3
  • 30
  • 49
  • What are you viewing the opened email in? Outlook? IOs Mail? Web browser? Gmail? – Ruskin Nov 21 '14 at 11:31
  • Possible duplicate of http://stackoverflow.com/questions/8836706/base64-html-embedded-images-not-showing-when-mailed – Ruskin Nov 21 '14 at 11:34

1 Answers1

4

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:

Community
  • 1
  • 1
Ruskin
  • 5,721
  • 4
  • 45
  • 62