Sending an email from swift 3

For sending email from your application you 

first Add UIMessage Package from for Application then Write this Code and connect them at your Storyboard :

import UIKit
import MessageUI

class SendDropMailVC: UIViewController , MFMailComposeViewControllerDelegate {
    @IBOutlet weak var subject: UITextField!
    @IBOutlet weak var Body: UITextView!
    override func viewDidLoad() {

    override func didReceiveMemoryWarning() {
    @IBAction func SendEmail(_ sender: AnyObject) {
        var SubjectText = "Your Subject:"
        SubjectText += subject.text!
        let messageBody = Body
        let toRecients = [""]
        let mc: MFMailComposeViewController = MFMailComposeViewController()
        mc.mailComposeDelegate = self
        mc.setMessageBody((messageBody?.text)!, isHTML: false)
        self.present(mc, animated: true, completion: nil)
    func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
        switch result.rawValue{
        case MFMailComposeResult.cancelled.rawValue:
            NSLog("Mail Cancelled")
        case MFMailComposeResult.saved.rawValue:
            NSLog("Mail Saved")
        case MFMailComposeResult.sent.rawValue:
            NSLog("Mail Sent")
        case MFMailComposeResult.failed.rawValue:
            NSLog("Mail Sent Failure: %@" , [error!.localizedDescription])
        self.dismiss(animated: true, completion: nil)

Add a UITextField! & UITextView! to your view with a button as you see in the picture

if its not clear send me your message


  1. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging…!!..Swift Online Training


Post a Comment