发送电子邮件,无需使用swift(OSX)进行确认

时间:2015-09-14 20:43:25

标签: macos swift email

我无法在OSX上使用Swift发送电子邮件。

它几乎完成了这项工作,但是没有发送电子邮件,而是在我的个人计算机上打开谷歌Chrome浏览器。

这是我的代码

import Cocoa

class ViewController: NSViewController, NSSharingServiceDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override var representedObject: AnyObject? {
        didSet {
        // Update the view, if already loaded.
        }
    }

    @IBAction func mag(sender: AnyObject) {
        let body = "BODY EMAIL"
        let shareItems = [body] as NSArray

        var service = NSSharingService(named: NSSharingServiceNameComposeEmail)
        service?.delegate = self
        service?.recipients = ["email@address.com"]

        let subject = "Subject!"
        service?.subject = subject

        service?.performWithItems(shareItems as [AnyObject])
    }          

}

0 个答案:

没有答案