Guest User

Untitled

a guest
Dec 12th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. import UIKit
  2. import MessageUI
  3.  
  4. class ViewController: UIViewController, MFMailComposeViewControllerDelegate {
  5.  
  6. override func viewDidLoad() {
  7. super.viewDidLoad()
  8. // Do any additional setup after loading the view, typically from a nib.
  9. }
  10.  
  11.  
  12. @IBAction func sendEmail(_ sender: Any) {
  13. if MFMailComposeViewController.canSendMail() {
  14. let mailComposer = MFMailComposeViewController()
  15. mailComposer.setSubject("Update about ios tutorials")
  16. mailComposer.setMessageBody("What is the update about ios tutorials on youtube", isHTML: false)
  17. mailComposer.setToRecipients(["abc@test.com"])
  18. mailComposer.mailComposeDelegate = self
  19. self.present(mailComposer, animated: true
  20. , completion: nil)
  21. } else {
  22. print("Email is not configured in settings app or we are not able to send an email")
  23. }
  24. }
  25.  
  26. //MARK:- MailcomposerDelegate
  27.  
  28. func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
  29. switch result {
  30. case .cancelled:
  31. print("User cancelled")
  32. break
  33.  
  34. case .saved:
  35. print("Mail is saved by user")
  36. break
  37.  
  38. case .sent:
  39. print("Mail is sent successfully")
  40. break
  41.  
  42. case .failed:
  43. print("Sending mail is failed")
  44. break
  45. default:
  46. break
  47. }
  48.  
  49. controller.dismiss(animated: true)
  50.  
  51. }
  52.  
  53. }
Add Comment
Please, Sign In to add comment