xcode – 从swift osx应用程序发送电子邮件

前端之家收集整理的这篇文章主要介绍了xcode – 从swift osx应用程序发送电子邮件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
从我的osx swift应用程序发送邮件时遇到问题.要发送邮件我使用下面的代码
import Foundation
import Cocoa


class sendemail : NSObject,NSSharingServiceDelegate{

func sendEmail()  throws
{
    print("enter email sending")
    let body = "This is an email for auto testing throug code."
    let shareItems = [body] as NSArray

    let service = NSSharingService(named: NSSharingServiceNameComposeEmail)

    service?.delegate = self
    service?.recipients = ["abc@dom.com"]

    let subject = "Vea Software"
    service?.subject = subject

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

}

我找到了此链接的源代码:@L_403_1@

但它没有用.

我还尝试按照以下说明从终端发送邮件

http://www.developerfiles.com/how-to-send-emails-from-localhost-mac-os-x-el-capitan/

它说 :

postfix/postfix-script: fatal: the Postfix mail system is not running

请帮我.

我可以手动从我的mac邮件应用程序发送邮件.

我在用

xcode 7.3,osx el captain and swift 2.2

解决方法

这对我有用:
class SendEmail: NSObject {
    static func send() {
        let service = NSSharingService(named: NSSharingServiceNameComposeEmail)!
        service.recipients = ["abc@dom.com"]
        service.subject = "Vea software"

        service.performWithItems(["This is an email for auto testing through code."])
    }
}

用法

SendEmail.send()
原文链接:https://www.f2er.com/iOS/332396.html

猜你在找的iOS相关文章