MFMailComposeViewController html电子邮件图像未发送

MFMailComposeViewController html电子邮件图像未发送,html,ios,base64,mfmailcomposeviewcontroller,Html,Ios,Base64,Mfmailcomposeviewcontroller,我正在尝试通过MFMailComposeViewController发送本地图像 我已经决定设置一个html正文,这样我就可以设计发送的电子邮件,并在正文中显示图像,使我的图像不在附件中 发送的图像从当前视图中提取。我的代码如下所示: MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init]; mailer.mailComposeDelegate = self; NSMutableString

我正在尝试通过MFMailComposeViewController发送本地图像

我已经决定设置一个html正文,这样我就可以设计发送的电子邮件,并在正文中显示图像,使我的图像不在附件中

发送的图像从当前视图中提取。我的代码如下所示:

MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
NSMutableString *emailBody = [[NSMutableString alloc] init];

[emailBody appendString:@"<html><body>"];

///////CREATE IMAGE TO SHARE////////
UIGraphicsBeginImageContextWithOptions(viewToSend.frame.size,YES,0.0);
[viewToSend.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
[img drawAtPoint:CGPointZero];
UIImage *outputImg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

//Convert image to a base64 string
NSData *imgData = UIImagePNGRepresentation(outputImg);
NSString *imageDataString = [imgData base64EncodedString];

[emailBody appendString:[NSString stringWithFormat:@"<p><b><img src='data:image/png;base64,%@'></b></p>",imageDataString]];
[emailBody appendString:@"</body></html>"];

[mailer setMessageBody:emailBody isHTML:YES];

[self presentViewController:mailer animated:YES completion:nil];
当显示MFMailComposeViewController时,图像显示在其中。但在收到的电子邮件中,图像丢失了

我的Base64编码方法取自Matt Gallagher创建的NSData+Base64类


发生了什么事?

您如何测试?某些电子邮件客户端/web界面不支持base64映像。你可能很难得到好的结果。你能链接到服务器上的图像吗?我正在给我发送电子邮件来测试它们。我用gmail打开它们。通过web inspector查看页面的源代码,在我的电子邮件内容中,我可以找到应用程序中构建的html代码。然而,正如我所说,并不是所有的电子邮件客户机生来都是平等的,您将很难处理嵌入HTML电子邮件中的图像。