JanScott JanScott - 1 year ago 53
iOS Question

Open eMail from App with predefined text in iOS

Hello i want to open the eMail program from my App and the body should already be defined. I can open the eMail but don't know how to define the body of the eMail as a given Parameter to show a given standard text. Anyone can help? Heres the code i use to open Email:

let email = "foo@bar.com"
let urlEMail = NSURL(string: "mailto:\(email)")

if UIApplication.sharedApplication().canOpenURL(urlEMail!) {
} else {

Answer Source

You can do it using MFMailComposeViewController:

let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self
mailComposerVC.setMessageBody("Body", isHTML: false)
self.presentViewController(mailComposerVC, animated: true, completion: nil)

Also, you need to implement mailComposeController:didFinishWithResult:error: from MFMailComposeViewControllerDelegate where you should dismiss MFMailComposeViewController