Swift 有图书馆 "SKPSMTPMessage" 吗?
Is there a library "SKPSMTPMessage" for Swift?
Swift 中是否有任何 SKPSMTPMessage 库可供使用? earlier i have used this tutorial which is in objective - c。我想要做的是使用 Swift.
在后台发送邮件
我不知道 Swift 中有任何电子邮件发送库,但您绝对可以在 Swift 应用程序中使用 Objective-C 教程中描述的库。所有 Objective-C 库都与 Swift 代码交叉兼容:只需使用 bridging header
.
只需将 skpsmtpmessage 与 cocoa pods 集成,只需添加:
pod 'skpsmtpmessage'
到您的 Podfile,然后这就是您从代码发送电子邮件的方式:
import skpsmtpmessage
class MailSender: NSObject, SKPSMTPMessageDelegate {
static let shared = MailSender()
func sendEmail(subject: String, body: String) {
let message = SKPSMTPMessage()
message.relayHost = "smtp.gmail.com"
message.login = "login@gmail.com"
message.pass = "password"
message.requiresAuth = true
message.wantsSecure = true
message.relayPorts = [587]
message.fromEmail = "login@gmail.com"
message.toEmail = "to@gmail.com"
message.subject = subject
let messagePart = [kSKPSMTPPartContentTypeKey: "text/plain; charset=UTF-8", kSKPSMTPPartMessageKey: body]
message.parts = [messagePart]
message.delegate = self
message.send()
}
func messageSent(_ message: SKPSMTPMessage!) {
print("Successfully sent email!")
}
func messageFailed(_ message: SKPSMTPMessage!, error: Error!) {
print("Sending email failed!")
}
}
Swift 中是否有任何 SKPSMTPMessage 库可供使用? earlier i have used this tutorial which is in objective - c。我想要做的是使用 Swift.
在后台发送邮件我不知道 Swift 中有任何电子邮件发送库,但您绝对可以在 Swift 应用程序中使用 Objective-C 教程中描述的库。所有 Objective-C 库都与 Swift 代码交叉兼容:只需使用 bridging header
.
只需将 skpsmtpmessage 与 cocoa pods 集成,只需添加:
pod 'skpsmtpmessage'
到您的 Podfile,然后这就是您从代码发送电子邮件的方式:
import skpsmtpmessage
class MailSender: NSObject, SKPSMTPMessageDelegate {
static let shared = MailSender()
func sendEmail(subject: String, body: String) {
let message = SKPSMTPMessage()
message.relayHost = "smtp.gmail.com"
message.login = "login@gmail.com"
message.pass = "password"
message.requiresAuth = true
message.wantsSecure = true
message.relayPorts = [587]
message.fromEmail = "login@gmail.com"
message.toEmail = "to@gmail.com"
message.subject = subject
let messagePart = [kSKPSMTPPartContentTypeKey: "text/plain; charset=UTF-8", kSKPSMTPPartMessageKey: body]
message.parts = [messagePart]
message.delegate = self
message.send()
}
func messageSent(_ message: SKPSMTPMessage!) {
print("Successfully sent email!")
}
func messageFailed(_ message: SKPSMTPMessage!, error: Error!) {
print("Sending email failed!")
}
}