加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

使用Swift发送电子邮件[closed]

发布时间:2020-12-14 06:06:17 所属栏目:百科 来源:网络整理
导读:如何在应用程序中发送一封电子邮件swift。比如说,你的用户想要在社交媒体应用程序中使用Parse(或不是)重置密码,但是你不想使用MessageUI,因为你想要它是自动的。我做了一些研究,发现它可能与mailgun,但我不知道如何使用它与swift和XCode 6.你能帮助我吗
如何在应用程序中发送一封电子邮件swift。比如说,你的用户想要在社交媒体应用程序中使用Parse(或不是)重置密码,但是你不想使用MessageUI,因为你想要它是自动的。我做了一些研究,发现它可能与mailgun,但我不知道如何使用它与swift和XCode 6.你能帮助我吗?
你当然可以。
import Foundation
import UIKit
import MessageUI

class ViewController: ViewController,MFMailComposeViewControllerDelegate {

    @IBAction func sendEmailButtonTapped(sender: AnyObject) {
        let mailComposeViewController = configuredMailComposeViewController()
        if MFMailComposeViewController.canSendMail() {
            self.presentViewController(mailComposeViewController,animated: true,completion: nil)
        } else {
            self.showSendMailErrorAlert()
        }
    }

    func configuredMailComposeViewController() -> MFMailComposeViewController {
        let mailComposerVC = MFMailComposeViewController()
        mailComposerVC.mailComposeDelegate = self // Extremely important to set the --mailComposeDelegate-- property,NOT the --delegate-- property

        mailComposerVC.setToRecipients(["nurdin@gmail.com"])
        mailComposerVC.setSubject("Sending you an in-app e-mail...")
        mailComposerVC.setMessageBody("Sending e-mail in-app is not so bad!",isHTML: false)

        return mailComposerVC
    }

    func showSendMailErrorAlert() {
        let sendMailErrorAlert = UIAlertView(title: "Could Not Send Email",message: "Your device could not send e-mail.  Please check e-mail configuration and try again.",delegate: self,cancelButtonTitle: "OK")
        sendMailErrorAlert.show()
    }

    // MARK: MFMailComposeViewControllerDelegate

    func mailComposeController(controller: MFMailComposeViewController!,didFinishWithResult result: MFMailComposeResult,error: NSError!) {
        controller.dismissViewControllerAnimated(true,completion: nil)

    }
}

源Andrew Bancroft

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读