Отправка почты, написать письмо (Send email) - Swift 5
import MessageUI
// Необходимо подписаться под протокол
MFMailComposeViewControllerDelegate
func sendEmail() {
if MFMailComposeViewController.
canSendMail() {
let mail =
MFMailComposeViewController()
mail.
mailComposeDelegate = self
mail.
setToRecipients(["@yoursite.com"])
mail.
setSubject("Subj")
mail.
setMessageBody("<p>You're so awesome!</p>",
isHTML: true)
present(
mail,
animated: true)
}
else {
// Если не удалось открыть приложение почта
}
}
extension VC: MFMailComposeViewControllerDelegate {
func mailComposeController(_ controller: MFMailComposeViewController,
didFinishWith result: MFMailComposeResult,
error: Error?) {
controller.
dismiss(
animated: true)
}
}
Возврат к списку