iosswiftemailmfmailcomposeviewcontroller

How to send an email without opening the mail composer iOS swift?


I am working iOS swift project. I want to send a mail with app itself. When the user clicks the submit button inside the app the mail needs to send in background or pop will be present inside the app without navigating into the mail composer.

        if MFMailComposeViewController.canSendMail() {
            let mail = MFMailComposeViewController()
            mail.mailComposeDelegate = self
            mail.setToRecipients([ApplicationModel.sharedInstance.mailAddress])
            mail.setSubject("Feedback: \(UserDefaults.Id)")
            mail.setMessageBody(sendBpodyMessage(), isHTML: false)
            present(mail, animated: true)
        } else {
            if let emailUrl = createEmailUrl(to: ApplicationModel.sharedInstance.mailAddress,
                                             subject: "Feedback", body: sendBpodyMessage()) {
                UIApplication.shared.open(emailUrl)
            }
        }

I refer so many answers that all were saying there is no way and apple did not have this feature. Is it possible or any other way Folks?

Most of them said to use API send into the own server. I will try it if I don’t have any option related to the above question.


Solution

  • Apple will not allow you to send email from the user's account without displaying a mail composer window to the user (for security reasons.) You will have to implement your own mail sending mechanism from your server if you want this (and still won't be able to send email from the user's account.)

    It's not that "Apple does not have this feature." It's that it would be a huge security hole. Apple explicitly blocks third parties from sending emails from the user's account except using a mail composer, and WILL NEVER ALLOW IT.

    Think about the potential for abuse if it was allowed. A spammer could release a "trojan horse" app like "flappy bird" for free: A fun, popular game. Millions of people download it. Unbeknownst to them, it starts sending out emails from their accounts, attempting to defraud their friends, or the online community at large