I am having trouble attaching a text file to an email. Nothing shows up as an attachment.
I've been staring at this for too long lol Please help me out. Thanks!
EDIT: After a little research, i found out I can not write theList variable because it is an array. It should be reduced first, then written.
let mailComposer = MFMailComposeViewController()
mailComposer.mailComposeDelegate = self
//Set Recipient
mailComposer.setToRecipients([email])
//Set Subject
mailComposer.setSubject("VanScan for " + "\(TechID.text!)" )
//Set Body Message
mailComposer.setMessageBody("The inventory for " + "\(TechID.text!)" + " is attached", isHTML: false)
if let filePath = NSBundle.mainBundle().pathForResource("\(filename)", ofType: "txt") {
//Does not print. Nil?
print("File path loaded.")
if let fileData = NSData(contentsOfFile: filePath) {
//Does not print. Nil?
print("File data loaded.")
mailComposer.addAttachmentData(fileData, mimeType: "text/plain", fileName: "\(filename)")
}
}
self.presentViewController(mailComposer, animated: true, completion: nil)
}