lee can lee can - 3 months ago 27x
Swift Question

Attach a PDF file to email - Swift

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)

Before sending the email, I can see attached
, but when I sent the email, it was sent without attachment and this is because I didn't attached correctly the file.


You are passing wrong mimeType to addAttachmentData(). Use application/pdf instead of pdf.