caipivara
2/11/2015 - 10:08 PM

Send email in iOS 8 with receipt and subject (you can add a body with possible HTML value too)

Send email in iOS 8 with receipt and subject (you can add a body with possible HTML value too)

extension YourViewController: MFMailComposeViewControllerDelegate {
	
	func mailComposeController(controller: MFMailComposeViewController!,
		didFinishWithResult result: MFMailComposeResult, error: NSError!) {
			/**
			Posible values:
			
			MFMailComposeResultSent.value: You sent the email.
			MFMailComposeResultSaved.value: You saved a draft of this email
			MFMailComposeResultCancelled.value: You cancelled sending this email.
			MFMailComposeResultFailed.value: Mail failed:  An error occurred when trying to compose this email
			other:  error
			*/
	}
}
if MFMailComposeViewController.canSendMail() {
	let subject = NSLocalizedString("MoreEmailSubject", comment: "")

	// It send the email async and notify its mailComposeDelegate with updates.
	// In the case of no internet connection on send, it will say that the status is sended and
	// will be sended automatically when the device get internet connection again.
	var mailComposeViewController = MFMailComposeViewController()
	mailComposeViewController.setToRecipients([GlobalConstants.CEBrokerData.Support.email])
	mailComposeViewController.setSubject(subject)
	mailComposeViewController.mailComposeDelegate = self
	
	presentViewController(mailComposeViewController, animated: true, completion: nil)
}