0

I'm trying to create an app whereby the user can send an email with an image attachment of their choice, I've done this so far with UITextfield. What ever the user types in the Text Field it is also included in the email.

My code is as follows:

@IBOutlet var fullName: UITextField!

@IBOutlet var latestPayslip: UIButton!

override func viewDidLoad() {
    super.viewDidLoad()
           let tap = UITapGestureRecognizer(target: self, action: #selector(UIInputViewController.dismissKeyboard))
    view.addGestureRecognizer(tap)
    // Do any additional setup after loading the view.
    fullName.addToolBar()
   
    fullName.delegate = self
    
}


@IBAction func sendEmail(_ sender: Any) {
    if MFMailComposeViewController.canSendMail() {
        let mail = MFMailComposeViewController()
        let emailFullName: String = fullName.text!
    
        mail.mailComposeDelegate = self
        mail.setToRecipients([“example@abc.com"])
        mail.setMessageBody("<p>FullName: \(emailFullName)</p>", isHTML: true)
        mail.setSubject("Application for RTO: ")

        present(mail, animated: true)
        
    }
}
   
private lazy var primaryTextFields: [UITextField] = {
    [fullName]
}()

@objc func dismissKeyboard() {
    //Causes the view (or one of its embedded text fields) to resign the first responder status.
    view.endEditing(true)
}

}

Sindano
  • 11
  • 1
  • 4
  • Does this answer your question? [How to add a image in email body using MFMailComposeViewController](https://stackoverflow.com/questions/12210571/how-to-add-a-image-in-email-body-using-mfmailcomposeviewcontroller) – JKo May 21 '22 at 00:20
  • Answers it half way I'd say, I would want the user to press a UIButton and choose an image from the gallery, then this particular image is included in the email – Sindano May 21 '22 at 01:46
  • then open photo gallery from a button pick a photo save photo in a variable then use that variable ? in mailComposer.addAttachment ? – Zeeshan Ahmad II May 21 '22 at 07:23

0 Answers0