iOS:发送带附件的电子邮件会自动添加另一个附加 (.txt) 文件

发布于 2024-12-29 14:07:10 字数 701 浏览 4 评论 0原文

我使用以下代码发送包含 NSData 对象内容的电子邮件(变量名称:data):

MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];

[controller setSubject:@"Subject"];
[controller addAttachmentData:data mimeType:@"application/pdf" fileName:@"Attachment"];
[controller setMessageBody:@"Please find attached the connections for..." isHTML:NO];

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

它将生成的 UIView 添加为 pdf 作为附件并发送电子邮件。一切都很好,除了一个问题:

收到电子邮件时,连同所附的 pdf 一起,还有另一个附加的 .txt 文件,其内容是:“从我的 iPad 发送”。如果我不附加 pdf 文件,“从我的 iPad 发送”消息将出现在电子邮件正文中,而不是附加文件中。

有谁知道如何解决这个问题?我不希望在消息中附加文本文件。

问候,

佩塔尔

I am using the following code to send an email with the contents of NSData object(with the variable name: data):

MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];

[controller setSubject:@"Subject"];
[controller addAttachmentData:data mimeType:@"application/pdf" fileName:@"Attachment"];
[controller setMessageBody:@"Please find attached the connections for..." isHTML:NO];

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

It adds a UIView generated as a pdf as an attachment and sends the email. It is all good, besides a single problem:

When the email is received, along with the attached pdf, there is another attached .txt file whose contents are: "Sent from my iPad" . If I do not attach the pdf, the "Sent from my iPad" message appears in the body of the email, instead in an attached file.

Does anyone have a clue how this can be resolved ? I do not want the text file to be attached in the message.

Regards,

Petar

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

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

发布评论

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

评论(1

总以为 2025-01-05 14:07:10

似乎当您发送带有附件的电子邮件时,其中的所有内容都被包装为多部分/混合消息,并且所有内容都编码为 Base64,包括消息正文和签名!所以它看起来像这样...

Content-Type: multipart/mixed;
    boundary="_003_81E0DB72B1F643FBAA40D9BCB66A11E4_"

--_003_81E0DB72B1F643FBAA40D9BCB66A11E4_
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: base64

SGkgTW9tIQ==

(即“Hi Mom!”编码为Base64)

--_003_81E0DB72B1F643FBAA40D9BCB66A11E4_
Content-Type: application/octet-stream; name="MyAttachment.xlsx"
Content-Description: MyAttachment.xlsx
Content-Disposition: attachment; filename="MyAttachment.xlsx"; size=15262
Content-Transfer-Encoding: base64

UEsDBBQABgAIAAAAIQA3Mb2RgAEAAIQFAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAAC

snip

AF81AABkb2NQcm9wcy9hcHAueG1sUEsFBgAAAAANAA0AaAMAACA4AAAAAA==

--_003_81E0DB72B1F643FBAA40D9BCB66A11E4_

Content-Type: text/html; name="ATT00001.htm"
Content-Description: ATT00001.htm
Content-Disposition: attachment; filename="ATT00001.htm"; size=91
Content-Transfer-Encoding: base64

PGh0bWw+PGJvZHkgYmdjb2xvcj0iI0ZGRkZGRiI+PGRpdj48L2Rpdj48ZGl2Pjxicj48YnI+U2VudCBmcm9tIG15IGlQYWQ8L2Rpdj48L2JvZHk+PC9odG1sPg==

(即

从我的 iPad 发送


作为 Base64)

--_003_81E0DB72B1F643FBAA40D9BCB66A11E4_--

即使您转到“设置>>”邮件、联系人、日历并删除签名,您仍然会附加一个空的 HTML 文档。

正确的长期答案可能是将其作为错误提交给苹果并等待。同时,如果这确实是一个严重的错误,我建议您自己生成整个多部分/混合电子邮件正文,而不带签名,并看看这是否会欺骗 MFMailComposeViewController 认为该电子邮件没有附件。就我个人而言,我想我只会告诉我的客户接受它。 :)

It seems that when you send an email with an attachment, everything in it is wrapped up as a multipart/mixed message, and everything encoded as Base64, including the message body and the signature! So it looks like this...

Content-Type: multipart/mixed;
    boundary="_003_81E0DB72B1F643FBAA40D9BCB66A11E4_"

--_003_81E0DB72B1F643FBAA40D9BCB66A11E4_
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: base64

SGkgTW9tIQ==

(that's "Hi Mom!" encoded as Base64)

--_003_81E0DB72B1F643FBAA40D9BCB66A11E4_
Content-Type: application/octet-stream; name="MyAttachment.xlsx"
Content-Description: MyAttachment.xlsx
Content-Disposition: attachment; filename="MyAttachment.xlsx"; size=15262
Content-Transfer-Encoding: base64

UEsDBBQABgAIAAAAIQA3Mb2RgAEAAIQFAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAAC

snip

AF81AABkb2NQcm9wcy9hcHAueG1sUEsFBgAAAAANAA0AaAMAACA4AAAAAA==

--_003_81E0DB72B1F643FBAA40D9BCB66A11E4_

Content-Type: text/html; name="ATT00001.htm"
Content-Description: ATT00001.htm
Content-Disposition: attachment; filename="ATT00001.htm"; size=91
Content-Transfer-Encoding: base64

PGh0bWw+PGJvZHkgYmdjb2xvcj0iI0ZGRkZGRiI+PGRpdj48L2Rpdj48ZGl2Pjxicj48YnI+U2VudCBmcm9tIG15IGlQYWQ8L2Rpdj48L2JvZHk+PC9odG1sPg==

(that's
<html><body bgcolor="#FFFFFF"><div></div><div><br><br>Sent from my iPad</div></body></html>
as Base64)

--_003_81E0DB72B1F643FBAA40D9BCB66A11E4_--

Even if you go to Settings >> Mail, Contacts, Calendars and erase the signature, you still get an empty HTML document attached.

The right long-term answer will probably be to submit this to Apple as a bug and wait. In the meantime, if this is really a showstopper bug, I'd suggest that you generate the entire multipart/mixed email body yourself, without the signature, and see if that fools MFMailComposeViewController into thinking that the email doesn't have an attachment. Personally, I think I'm just going to tell my customer to live with it. :)

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