I'm using the MFMailComposerViewController
to send an email from an iOS app. The mail works except when trying to add an image. The issue with the image for me is getting it using
I've seen other examples that use something like: UIImage *emailImage = [UIImage imageNamed:@"myImageName.png"];
to add the image. My image is taken from a database table using [self.photo objectForKey:kPhotoPictureKey];
// mail
// Email Subject
NSString *emailTitle = @"Join. Download the iPhone app";
// Email Content
NSString *messageBody = @"http://www..com/";
// To address
NSArray *toRecipents = [NSArray arrayWithObject:@""];
UIImageView *mailImage = [[UIImageView alloc] init];
mailImage.image = [UIImage imageNamed:@"1.png"]; // placeholder image
mailImage.file = [self.photo objectForKey:kPhotoPictureKey];
[mailImage loadInBackground];
NSString *messageBody = [NSString stringWithFormat:@"http://www.example.com/<p><b><img src='data:image/png;base64,%@'></b></p>",mailImage.image];
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setMessageBody:messageBody isHTML:NO];
[mc setToRecipients:toRecipents];
// Present mail view controller on screen
[self presentViewController:mc animated:YES completion:NULL];