Here I’m exploring how to send mails programatically in Swift. Apple has provided MessageUI framework to implement mail functionality in your app. This framework has MFMailComposeViewController class which provides an interface to send/manage emails. We can use this controller to display a user interface within our app.
Let’s learn how it works.
1- Create an instance of MFMailComposeViewController.
let mailComposeViewController = MFMailComposeViewController()
2- Now check if your device can send email or not.
This will return true if device can send mail, else false will be returned.. reason of false could be any. It may be because of no mail account setup.
3- Now conform the delegate methods to handle the listeners.