How to insert an image into the body of an HTML email message in iOS

I am trying to include an image in the body of an HTML letter sent from an iPad. It seems impossible. I tried to use the CID approach, but it seems in iOS it is not possible to get / set the CID of attachments.

I also tried to insert an image with src="data:image/png;base64, blahblahblah" . When you compose mail, it works, but nothing appears when you receive mail.

Any ideas?

Details : We are not looking for solutions in which JPEG / PNG is attached at the bottom of the letter. This is easy to do with [composer addAttachmentData:mimeType:fileName:] .

We are looking for a solution in which the image is embedded inline in electronic format in HTML format. You can wrap the link around this IMG tag so that when the recipient clicks on the IMG, he / she will be linked to the iTunes application page.

+7
source share
3 answers

Download the NSData+base64 category from github .

Then follow these steps:

 NSData *imageData = [NSData dataWithContentsOfFile:pathInDocumentDirectory(imagePath)]; NSString *base64String = [imageData base64EncodedString]; NSString *imageString = [NSString stringWithFormat:@"data:image/png;base64,%@", base64String]; 

Finally, put the imageString in the body of the HTML where you want this image to appear.

Hope this helps!

+6
source

From iphone email attachment

 MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; picker.mailComposeDelegate = self; [picker setSubject:@"Hello"]; // Set up recipients NSArray *toRecipients = [NSArray arrayWithObject:@" first@example.com "]; NSArray *ccRecipients = [NSArray arrayWithObjects:@" second@example.com ", @" third@example.com ", nil]; NSArray *bccRecipients = [NSArray arrayWithObject:@" fourth@example.com "]; [picker setToRecipients:toRecipients]; [picker setCcRecipients:ccRecipients]; [picker setBccRecipients:bccRecipients]; // Attach an image to the email NSString *path = [[NSBundle mainBundle] pathForResource:@"rainy" ofType:@"png"]; NSData *myData = [NSData dataWithContentsOfFile:path]; [picker addAttachmentData:myData mimeType:@"image/png" fileName:@"rainy"]; // Fill out the email body text NSString *emailBody = @"It is raining"; [picker setMessageBody:emailBody isHTML:NO]; [self presentModalViewController:picker animated:YES]; [picker release]; 
+1
source

To show the image in gmail, follow these steps:

 MFMailComposeViewController *mailCont = [[MFMailComposeViewController alloc] init]; mailCont.mailComposeDelegate = self; NSMutableString *emailBody = [[NSMutableString alloc] initWithCapacity:20]; NSString *linkimg = @"https://idrivethru.com/iDriveThruWeb/faces/javax.faces.resource/idrivethru_logo.png?ln=images"; //Add the image [emailBody appendFormat:@"<p><a href = 'https://idrivethru.com/'> <img src='%@' align='centre' alt='iDriveThru.com'> </a></p><br/>", linkimg]; [emailBody appendString:@"<p>This is an email with an embeded image right <b>above</b> this text</p>"]; //NSLog(@"%@",emailBody); [mailCont setMessageBody:emailBody isHTML:YES]; [self presentViewController:mailCont animated:YES completion:nil]; 
0
source

All Articles