将PDF文件附加到电子邮件 - Swift [英] Attach a PDF file to email - Swift

查看:179
本文介绍了将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)

发送电子邮件之前,我可以看到附加的 .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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆