1

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)
    }
Danny06191
  • 133
  • 1
  • 9
  • Are you sure that is your real code? The delegate method shouldn't even compile as you are passing types instead of values. – Abizern Oct 26 '15 at 04:18
  • Go through this link.It may help you.http://www.devshed.com/c/a/php/dynamically-attaching-files-with-swift-mailer/ –  Oct 26 '15 at 04:18
  • So Abizern, is there a way around that? The data is determined in real time, not compiled with a set value. – Danny06191 Oct 26 '15 at 04:28

0 Answers0