
How can we attach an image in MFMailComposeViewController?

- (void)createEmail {
NSMutableString *emailBody = [[[NSMutableString alloc] initWithString:@"<html><body>"] retain];
[emailBody appendString:@"<p>Some email body text can go here</p>"];
UIImage *emailImage = [UIImage imageNamed:@"myImageName.png"];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(emailImage)];
NSString *base64String = [imageData base64EncodedString];
[emailBody appendString:[NSString stringWithFormat:@"<p><b><img src='data:image/png;base64,%@'></b></p>",base64String]];
[emailBody appendString:@"</body></html>"];
NSLog(@"%@",emailBody);
//mail composer window
MFMailComposeViewController *emailDialog = [[MFMailComposeViewController alloc] init];
emailDialog.mailComposeDelegate = self;
[emailDialog setSubject:@"My Inline Image Document"];
[emailDialog setMessageBody:emailBody isHTML:YES];
[self presentModalViewController:emailDialog animated:YES];
[emailDialog release];
[emailBody release];
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.