从Swift OSX应用程序发送电子邮件 [英] send email from swift osx application

查看:105
本文介绍了从Swift OSX应用程序发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从osx swift应用程序发送邮件时遇到问题.要发送邮件,我使用了以下代码

I am facing problem on sending mail from my osx swift application. To send mail i used the below code

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])
}

}

我从此链接找到了源: https://www.veasoftware.com/posts/send-email-in-swift-xcode-62-os-x-1010-tutorial

i have found the source form this link:https://www.veasoftware.com/posts/send-email-in-swift-xcode-62-os-x-1010-tutorial

但是它不起作用.

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

I also tried to send mail from terminal following this instructions:

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邮件应用程序手动发送邮件.

I can send mail from my mac mail app manually which is configured.

我正在使用

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()

这篇关于从Swift OSX应用程序发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆