我有一个允许用户通过 MFMailcomposeViewController 发送电子邮件的应用程序。
composeVC.setToRecipients(["email@gmail.com"])
在同一个视图控制器中,我有一个标签,它代表从 Firestore 下载的人员的电子邮件。我怎样才能setToRecipients代替 ( ["email@gmail.com"]) 到 ( ["mailRepresentedLabel@gmail.com"])
我希望它从邮件代表标签中提取数据并将其自动添加到收件人,因此最终用户不需要将电子邮件添加到 setToRecipient 它将自动从 mailRepresentedLabel 中提取
请帮忙。
我当前的代码看起来像这样
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)
}
}```