In iOS, want to send a email with embedded images and text in the body of the email ( not attachment) using mail composer. Can anybody help ?
Asked
Active
Viewed 1,808 times
-4
-
The down votes don't build confidence in our new member; no need to pile it on... – raffian Apr 02 '13 at 14:41
2 Answers
3
You can use the HTML content with img tag for doing this. You can use the following code:
NSMutableString *imgContent = [[[NSMutableString alloc] initWithString:@"<html><body>"] retain];
UIImage *imageData = [UIImage imageNamed:@"Midhun.png"];
NSData *imageDataInBase64 = [NSData dataWithData:UIImagePNGRepresentation(imageData)];
NSString *base64String = [imageDataInBase64 base64EncodedString];
[imgContent appendString:[NSString stringWithFormat:@"<p><b><img src='data:image/png;base64,%@'></b></p>",base64String]];
[imgContent appendString:@"</body></html>"];
MFMailComposeViewController *emailWin = [[MFMailComposeViewController alloc] init];
[emailWin setMessageBody:imgContent isHTML:YES];

Midhun MP
- 103,496
- 31
- 153
- 200
-
Thanks Mithun MP. With this code the image is showing in the body of the mail composer but once we send that, it is not received in windows mail . It does get reflected in Iphone/Ipad yet. – Deep_rocks Apr 03 '13 at 07:44
2
MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
[mailComposer setMailComposeDelegate:self];
if ([MFMailComposeViewController canSendMail]) {
[mailComposer setToRecipients:[NSArray arrayWithObjects:@"kmlshyadav6@gmail.com", nil]];
[mailComposer setSubject:@"Awesome Image(ur message or subject)"];
[mailComposer setMessageBody:@"Hey,\n\nCheck out this awesome image!\n\n" isHTML:NO];
[mailComposer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
UIImage *lion = imageView.image;
NSData *lionData = UIImageJPEGRepresentation(lion, 1);
[mailComposer addAttachmentData:lionData mimeType:@"image/jpeg" fileName:@"01-Mac-OS-X-Lion.jpg"];
}
[self presentModalViewController:mailComposer animated:YES]; [mailComposer release];
} else {
[mailComposer release];
}

kamalesh kumar yadav
- 966
- 1
- 9
- 19
-
Thanks Kamalesh , with this method , the picture is getting attahced and does not reflect in the body of the mail. – Deep_rocks Apr 03 '13 at 07:43
-
We are using this code but the image is showing in the body of the mail composer but once we send that, it is not received in windows mail . It does get reflected in Iphone/Ipad yet.Can you please suggest me. – Deep_rocks Apr 03 '13 at 14:34