I tried to open a mailer in the app using the MFMailComposeViewController and send an email, but it didn't work, so I asked this time.The code that you think is relevant is as follows.
However, if you look at the print log, it says Email Sent Successfully and it is successful.The mail I sent was kept in the email folder on my iPhone, and it seemed that I could not send it completely.
If anyone knows how to solve it, please take care of it.
@IBAction funcmail_send(_sender:Any){
if MFMailComposeViewController.canSendMail()==false{
print("Email Send Failed")
return
}
letmailViewController = MFMailComposeViewController()
mailViewController.mailComposeDelegate=self
// subject line
let subject = String(id)
// mailViewController.setSubject("Bug Report")
mailViewController.setSubject(subject)
let to Recipients = ["[email protected]" ]
mailViewController.setToRecipients (toRecipients)
let body=list [row_now]
mailViewController.setMessageBody(body, isHTML:false)
ifMFMailComposeViewController.canSendMail(){
self.present(mailViewController, animated:true)//, completion:nil
} else{
self.showSendMailErrorAlert()
}
}
funcmailComposeController(_controller:MFMailComposeViewController, didFinishWithresult:MFMailComposeResult, error:Error?){
switchresult.rawValue{
caseMFMailComposeResult.cancelled.rawValue:
print("Email Send Cancelled")
break
caseMFMailComposeResult.saved.rawValue:
print("Email Saved as a Draft")
break
caseMFMailComposeResult.sent.rawValue:
print("Email Sent Successfully")
break
caseMFMailComposeResult.failed.rawValue:
print("Email Send Failed")
break
default:
print("Email Default Case")
break
}
self.dismiss(animated:true, completion:nil)
}
That's the specification for now, and it's working correctly.
https://developer.apple.com/reference/messageui/mfmailcomposeresult/1616878-sent
The email message was queued in the user's outbox.It is ready to send the next time the user connects to email.
As mentioned above, MFMailComposeResult.sent
indicates that it was saved in the "outbox" or "send" folder.It's not whether the email was sent or not.A typical example is when a network is not connected.Mail stored in the Send folder will be sent automatically the next time you access the email.app, depending on your settings.
© 2024 OneMinuteCode. All rights reserved.