MFMailComposeViewController html电子邮件图像未发送

时间:2014-02-28 14:12:17

标签: html ios base64 mfmailcomposeviewcontroller

我正在尝试通过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时,图像会显示在其中。但在收到的电子邮件中,图片丢失了。

我的base 64编码方法取自NSData + Base64

创建的类Matt Gallagher

发生了什么事?

0 个答案:

没有答案