Swift - 在 Cocoa 中发送邮件

2017-05-09  本文已影响204人  张嘉夫

10.9 开始可以使用 ** NSSharingService**(支持附件)!

    let emailImage          = NSImage.init(named: "待分享的图片")!
    let emailBody           = "邮件正文"
    let emailService        =  NSSharingService.init(named: NSSharingServiceNameComposeEmail)!
    emailService.recipients = ["support@myapp.com"]
    emailService.subject    = "App支持"

    if emailService.canPerform(withItems: [emailBody,emailImage]) {
        emailService.perform(withItems: [emailBody,emailImage])
    } else {
        // 无法发送邮件,可能是因为没有配置邮件账户
        // 将邮件地址和说明用 alert 显示给用户

    }
上一篇下一篇

猜你喜欢

热点阅读