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.

Akshay Somkuwar
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)}

Thank you for reading πŸ™

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Akshay Somkuwar
Akshay Somkuwar

Written by Akshay Somkuwar

iOS | MacOS | React Native Developer..

No responses yet

Write a response