9 macos xcode postfix-mta swift swift2
我在从我的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])
}
}
Run Code Online (Sandbox Code Playgroud)
我找到了这个链接的源代码:https://www.veasoftware.com/posts/send-email-in-swift-xcode-62-os-x-1010-tutorial
但它没有用.
我还尝试按照以下说明从终端发送邮件:
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
Run Code Online (Sandbox Code Playgroud)
请帮我.
我可以手动从我的mac邮件应用程序发送邮件.
我在用
xcode 7.3, osx el captain and swift 2.2
Run Code Online (Sandbox Code Playgroud)
Cod*_*ent 13
这对我有用:
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."])
}
}
Run Code Online (Sandbox Code Playgroud)
用法:
SendEmail.send()
Run Code Online (Sandbox Code Playgroud)
Swift 4.2:
class SendEmail: NSObject {
static func send() {
let service = NSSharingService(named: NSSharingService.Name.composeEmail)!
service.recipients = ["email@yourEmail.eu"]
service.subject = "Email Subject"
service.perform(withItems: ["Email Content"])
}
}
Run Code Online (Sandbox Code Playgroud)
用法: SendEmail.send()
| 归档时间: |
|
| 查看次数: |
4008 次 |
| 最近记录: |