iPhone MessageUI 电子邮件附件未发送给收件人
我正在尝试使用 MessageUI 框架将图像和 pdf 附加到电子邮件中。我遵循 MailComposer Apple 文档中的示例。
在 iPhone 上,它似乎工作得很好,图像和 pdf 都按预期显示在发送邮件窗口的正文中。
然而,当我在 MacBook 上收到电子邮件时,出现两个问题。
1) myImage.png 显示为附件,尺寸正确,但完全空白
2) myPDF.pdf 根本不显示为附件
但是,当我在 iPhone 上收到邮件时,myImage.png 出现美好的。不过,myPDF.pdf 仍然没有出现在我的 iPhone 上的邮件中。
希望有人能够阐明可能发生的事情。
以下是相关代码:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Test Email"];
// Attach an image to the email
NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"myImage" ofType:@"png"];
NSData *imageData = [NSData dataWithContentsOfFile:imagePath];
[picker addAttachmentData:imageData mimeType:@"image/png" fileName:@"myImage"];
// Attach a PDF file to the email
NSString *pdfPath = [[NSBundle mainBundle] pathForResource:@"myPDF" ofType:@"pdf"];
NSData *pdfData = [NSData dataWithContentsOfFile:pdfPath];
[picker addAttachmentData:pdfData mimeType:@"application/pdf" fileName:@"myPDF"];
// Fill out the email body text
NSString *emailBody = @"This is a test.";
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release];
编辑 我没有将图像和 PDF 保存并检索到我的 mainBundle,而是使用 NSDocumentsDirectory,一切正常。
I am trying to attach an image and a pdf to an email using the MessageUI framework. I followed the MailComposer example in the Apple documentation.
On the iPhone it seems to work perfectly, the image and the pdf both show up in the body of the send mail window as expected.
However, when I receive the email on my MacBook there are two problems.
1) myImage.png shows up as an attachment and is the correct dimensions but is totally blank
2) myPDF.pdf doesn't show up as an attachment at all
But, when I receive the mail on my iPhone, myImage.png shows up fine. myPDF.pdf still doesn't show up in mail on my iPhone though.
Hope someone can shed some light on what might be happening.
Here is the relevant code:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Test Email"];
// Attach an image to the email
NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"myImage" ofType:@"png"];
NSData *imageData = [NSData dataWithContentsOfFile:imagePath];
[picker addAttachmentData:imageData mimeType:@"image/png" fileName:@"myImage"];
// Attach a PDF file to the email
NSString *pdfPath = [[NSBundle mainBundle] pathForResource:@"myPDF" ofType:@"pdf"];
NSData *pdfData = [NSData dataWithContentsOfFile:pdfPath];
[picker addAttachmentData:pdfData mimeType:@"application/pdf" fileName:@"myPDF"];
// Fill out the email body text
NSString *emailBody = @"This is a test.";
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release];
EDIT Instead of saving and retrieving my image and PDF to my mainBundle I used NSDocumentsDirectory and everything worked fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
关于图像附件,我也遇到了同样的问题。使用这个,我能够发送并实际接收附加图像:
抱歉,我没有尝试发送 pdf。
只是我的两分钱,
问候。
I had the same problem regarding the image attachment. Using this, I was able to send and actually receive the attached image:
I didn't try pdf sending, sorry.
Just my two cents,
Regards.
我不知道它是否真的会导致您的问题,但大多数人似乎在 addAttachmentData 的 fileName 参数上包含文件扩展名,即
I don't know if it actually would cause your problem, but most people seem to include filename extensions on the fileName parameter to addAttachmentData, i.e.
试试这个,这个对我有用。
Try This ,This one worked for me .
我遇到了同样的问题,我确定 MFMailComposeViewController 正在使用 7 位传输
PDF
文件打包MIME
。 /strong> 编码,而不是引用打印或 base-64 编码。显然,您不能使用 7 位编码通过电子邮件发送二进制文件。因此,要么我缺少 MFMailComposeViewController 上的传输编码设置,要么该对象有严重的缺点。I have had the same problem and I determined that the
MFMailComposeViewController
is packaging theMIME
for thePDF
file with 7-bit transfer encoding, rather than quoted-printable or base-64 encoding. Obviously you cannot email binary files using 7-bit encoding. So either there is a transfer-encoding setting on aMFMailComposeViewController
that I am missing or this object has a serious shortcoming.我遇到了这个,因为我遇到了同样的问题......有点旧,但万一有人遇到这个,这对我有帮助......
我能够像往常一样添加我的附件(使用 6 个不同类型的附件) ...它们会出现在电子邮件正文中...但收件人永远不会收到所有附件...只有一个。
我将文件拖放到编辑器中(拖放到 m 或 h 文件中),它显示了文件路径。事实证明,我忽略了将第一个文件复制到我的项目中,因此该应用程序从我的本地驱动器中提取,然后停止,因为我尝试附加的其他文件不在同一文件夹中。当我从同一位置拉出所有附件后,它们都很好地拉动了。
希望对某人有帮助。
I came across this as I was having the same issue...little old but in case anyone comes across this here is what helped me....
I was able to add my attachments in as usual (using 6 attachments of various types)...they would show up in the email body...but the receiver would never get all of the attachments....only one.
I pulled the files into my editor (drag and drop into your m or h files) and it showed the file path. Turns out that I had neglected to copy the first file to my project so the app was pulling from my local drive and then stopping as the other files I was trying to attach were not in the same folder. Once I pulled all of the attachments from the same location they all pulled in fine.
Hope that helps someone.