MFMailComposer -- 附加带有 HTML 的图像

发布于 2024-12-06 11:35:18 字数 533 浏览 2 评论 0原文

我正在尝试发送一封带有图像附件并打开 HTML 的电子邮件。问题是,当 HTML 启用时,图像会内嵌显示,而不是作为附件显示(我使用 gmail)。

如果我设置 isHTML:NO 那么图像会正确显示为可下载附件。如何将图像作为带有 h​​tml 消息的附件发送?

NSData *imageAttachment = UIImageJPEGRepresentation(myUIImage,1);

MFMailComposeViewController *mailView = [[MFMailComposeViewController alloc] init];
[mailView setSubject:@"My Email Subject!"];
[mailView addAttachmentData:imageAttachment mimeType:@"image/jpeg" fileName:@"imageAttachment.jpg"];
[mailView setMessageBody:messageBody isHTML:YES];

谢谢~!!

I am trying to send an email with an image attachment and HTML turned on. The problem is that when HTML is on, the image appears inline instead of as an attachment (I use gmail).

If I set isHTML:NO then the image properly shows up as a downloadable attachment. How can I send the image as an attachment with an html message?

NSData *imageAttachment = UIImageJPEGRepresentation(myUIImage,1);

MFMailComposeViewController *mailView = [[MFMailComposeViewController alloc] init];
[mailView setSubject:@"My Email Subject!"];
[mailView addAttachmentData:imageAttachment mimeType:@"image/jpeg" fileName:@"imageAttachment.jpg"];
[mailView setMessageBody:messageBody isHTML:YES];

Thanks~!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紫﹏色ふ单纯 2024-12-13 11:35:18

您附加图像的方法是正确的,您得到的结果也符合标准。

无论哪种方式,最终用户(无论是否使用 Gmail)都应该获得附件。

例如,Windows Live Mail 应该将其视为附件,而在 Mac OS 中使用“邮件”时,您会看到内联图像。

Your method for attaching the image is correct, and the results you are getting are also up to par.

Either way, the end user (whether they use Gmail or not) should get the attachment.

For instance, Windows Live Mail should see it as an attachment, where as using Mail in Mac OS, you would see the image inline.

窗影残 2024-12-13 11:35:18

您必须将图像添加为附件。您在 HTML 中看到的呈现的电子邮件无法通过缺少图像 URL 正确呈现。

这是一个例子:需要注意的是,如果您想包含 PDF 之类的内容,则必须包含图像,否则 mfmailcomposer 将失败......这是苹果错误。

我找到了解决方案...我在苹果雷达上提交了一个关于它的错误。 MFMailcomposer 有一个错误,您必须发送图像以及额外的附件才能使 pdf 之类的奇怪项目正常工作...尝试此操作并将 pdf 替换为您的卡片:

MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
NSString *emailSubject = [NSString localizedStringWithFormat:@"MedicalProfile"];
[controller setSubject:emailSubject];


NSString *fileName = [NSString stringWithFormat:@"%@.pdf", profileName];
NSString *saveDirectory = NSTemporaryDirectory();
NSString *saveFileName = fileName;
NSString *documentPath = [saveDirectory stringByAppendingPathComponent:saveFileName];  

*** YOU MUST INCLUDE AN IMAGE OR THE PDF ATTATCHMENT WILL FAIL!!!***
// Attach a PDF file to the email 
NSData *pdfData = [NSData dataWithContentsOfFile:documentPath];    
[controller addAttachmentData:pdfData mimeType:@"application/pdf" fileName:fileName];


// Attach an image to the email
NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"miniDoc" ofType:@"png"];
NSData *imageData = [NSData dataWithContentsOfFile:imagePath];
[controller addAttachmentData:imageData mimeType:@"image/png" fileName:@"doctor"];


[controller setMessageBody:[NSString stringWithFormat:@"%@'s Medical Profile attatched!", profileName] isHTML:NO];

[self presentModalViewController:controller animated:YES];
controller.mailComposeDelegate = self;
[controller release];

You have to add the images as an attachment. The rendered email that you see with HTML doesn't get rendered properly with the missing image URL.

here is an example: the caveat is that if you want to include things like a PDF you must include an image otherwise mfmailcomposer will fail... this in an apple bug.

I found the solution... Isubmitted a bug on Apple radar about it. MFMailcomposer has a bug in which you have to send an image along with your extra attachments in order to get the weird items like a pdf to work... try this and replace the pdf with your card:

MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
NSString *emailSubject = [NSString localizedStringWithFormat:@"MedicalProfile"];
[controller setSubject:emailSubject];


NSString *fileName = [NSString stringWithFormat:@"%@.pdf", profileName];
NSString *saveDirectory = NSTemporaryDirectory();
NSString *saveFileName = fileName;
NSString *documentPath = [saveDirectory stringByAppendingPathComponent:saveFileName];  

*** YOU MUST INCLUDE AN IMAGE OR THE PDF ATTATCHMENT WILL FAIL!!!***
// Attach a PDF file to the email 
NSData *pdfData = [NSData dataWithContentsOfFile:documentPath];    
[controller addAttachmentData:pdfData mimeType:@"application/pdf" fileName:fileName];


// Attach an image to the email
NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"miniDoc" ofType:@"png"];
NSData *imageData = [NSData dataWithContentsOfFile:imagePath];
[controller addAttachmentData:imageData mimeType:@"image/png" fileName:@"doctor"];


[controller setMessageBody:[NSString stringWithFormat:@"%@'s Medical Profile attatched!", profileName] isHTML:NO];

[self presentModalViewController:controller animated:YES];
controller.mailComposeDelegate = self;
[controller release];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文