I have an application that allows users to send emails by MFMailcomposeViewController.
composeVC.setToRecipients(["[email protected]"])
In the same view controller i have a label which is representing the email of the people which is downloaded from Firestore. How can i setToRecipients
instead of (["[email protected]"]
) to (["[email protected]"]
)
I want it to pull the data from mail represented label and add it automatically to the recipient so the end user is not required to add the email to setToRecipient it will be automatically pulled from mailRepresentedLabel
Please help.
My current code is look like this
if !MFMailComposeViewController.canSendMail() {
print("Не удается отправить Имэйл")
return
}
let composeVC = MFMailComposeViewController()
composeVC.mailComposeDelegate = self
// Configure the fields of the interface.
composeVC.setToRecipients(["\(String(describing: mailRepLabel))"])
composeVC.setSubject("Register your client details with us")
composeVC.setMessageBody("Dear agent please register your client with us by replying on that email in order for us to track the information that this client is came with you. if aftersometime the client would like to come without you we will always have the information that this client is came with you and we will send him back to you. Please reply with the following details: Client Name, Passport number Property Managers name.", isHTML: false)
// Present the view controller modally.
self.present(composeVC, animated: true, completion: nil)
print("done")
}
}
extension AgentViewController: MFMailComposeViewControllerDelegate {
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
if let _ = error {
controller.dismiss(animated: true)
return
}
switch result {
case .cancelled:
print("Canceled")
case.failed:
print("Failed to send")
case.saved:
print("Saved")
case.sent:
print("Email Sent")
}
controller.dismiss(animated: true)
}
}```
You can access the text content of your label with the text
attribute. So... Something like this?
mailComposer.setToRecipients([mailRepLabel.text])