How to embed image in html in MFMailComposeViewController for iPhone

懵懂的女人 提交于 2019-12-18 11:48:15

问题


I am trying to embed a bunch of small images in an html table which I want to send using MFMailComposeViewController. After doing some search I figured out almost everyone is suggesting "NSData+Base64 by Matt Gallagher" class to encode the photo in Base64encoding and embedding it into html. While it looks to work on iPhone and with some email servers but Gmail and Yahoo do not show the images embedded this way. This problem is mentioned here as well.

I was wondering if anyone has a better solution for this. I don't want to upload photos on the web and put the link in the html code. I would like the image to be attached to the email and show up as an inline image within html text,table,...


回答1:


This unfortunately cannot be done currently in the way that you desire. Inline images in HTML email use separate MIME parts that are referenced via a content-id from the body of the message. MFMailComposeViewController doesn't give you control over the MIME structure of the message, and doesn't let you add inline referenced content parts.

Embedding image data into <img> tags as base64 can work on some combinations-- it's partly a function of email client and partly of the browser ultimately used to render it, but as you have noticed, it's not broadly portable.




回答2:


I'm not sure about adding to HTML, but here's how I add images as attachments:

UIImage *image = [UIImage imageNamed:@"myImage.png"];
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
composer.mailComposeDelegate = self;

NSData *data = UIImagePNGRepresentation(image);
[composer addAttachmentData:data mimeType:@"image/png" fileName:@"curse"];
[composer setMessageBody:@"" isHTML:NO];
[self presentModalViewController:composer animated:YES];
[composer release];

Now all you need is to change the body to be HTML and a way to reference the attached image from the HTML.




回答3:


Upload the image to some hosting site, copy the link and put that to

<img src='the link.png' /> html on your email message body.


来源:https://stackoverflow.com/questions/4239398/how-to-embed-image-in-html-in-mfmailcomposeviewcontroller-for-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!