将 PDF 文件附加到电子邮件 - Swift [英] Attach a PDF file to email - Swift
本文介绍了将 PDF 文件附加到电子邮件 - Swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想发送带有 PDF 附件的电子邮件.我创建了 PDF 文件,然后我做了以下我认为是错误的:
I want to send email with a PDF attachment. I created PDF file, then I did the following which is wrong I believe:
// locate folder containing pdf file
let documentsPath = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)[0] as! String
let pdfFileName = documentsPath.stringByAppendingPathComponent("chart.pdf")
let fileData = NSData(contentsOfFile: pdfFileName)
mc.addAttachmentData(fileData, mimeType: "pdf", fileName: chart)
在发送邮件之前,我可以看到附件chart.pdf
,但是当我发送邮件时,它发送时没有附件,这是因为我没有正确附加文件.>
Before sending the email, I can see attached chart.pdf
, but when I sent the email, it was sent without attachment and this is because I didn't attached correctly the file.
推荐答案
您将错误的 mimeType
传递给 addAttachmentData()
.使用 application/pdf
而不是 pdf
.
You are passing wrong mimeType
to addAttachmentData()
. Use application/pdf
instead of pdf
.
这篇关于将 PDF 文件附加到电子邮件 - Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文