Mail Composer in few lines of code(Swift)
In most of the applications we have contact us or reach us tab where user can send email to the company or support.
1 min readDec 12, 2018
Lets get started π¨βπ»
#Step 1:
Import MessageUI
import MessageUI
#Step 2:
Add MFMailComposeViewControllerDelegate delegate
MFMailComposeViewControllerDelegate
#Step 3:
Add this code in your button action
if MFMailComposeViewController.canSendMail() { let composer = MFMailComposeViewController() composer.mailComposeDelegate = self composer.setToRecipients(["emailIdWhereYouWantToSendTHeMail"]) self.present(composer, animated: true, completion: nil)}
#Step 4:
Add this delegate to dismiss mail composer when cancel is clicked or finished sending mail
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) { pickerV.isHidden = true self.dismiss(animated: true, completion: nil)}