美文网首页
iOS MFMailComposeViewController

iOS MFMailComposeViewController

作者: gaookey | 来源:发表于2020-11-09 20:19 被阅读0次
    import MessageUI
    
    let mail = MFMailComposeViewController()
    mail.mailComposeDelegate = self
    mail.setSubject("邮件主题")
    mail.setMessageBody("邮件内容", isHTML: true)
    
    // 收件人
    mail.setToRecipients(["xxx@xxx.com"])
    // 抄送
    mail.setCcRecipients(["xxx@xxx.com"])
    // 密送
    mail.setBccRecipients(["xxx@xxx.com"])
    
    if let image = UIImage(named: "image"),
       let data = image.jpegData(compressionQuality: 1) {
        
        // 添加附件。 mimeType: http://www.iana.org/assignments/media-types/
        mail.addAttachmentData(data, mimeType: "image/png", fileName: "image")
    }
    // 设置首选发送电子邮件地址
    //mail.setPreferredSendingEmailAddress("xxx@xxx.com")
    
    present(mail, animated: true, completion: nil)
    
    // MARK: - MFMailComposeViewControllerDelegate
    func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
        
        mail.dismiss(animated: true, completion: nil)
    }
    

    相关文章

      网友评论

          本文标题:iOS MFMailComposeViewController

          本文链接:https://www.haomeiwen.com/subject/yderbktx.html