一个连接到 Postmark API 以可靠发送电子邮件的 Swift 包。
虽然目前可以发送基本电子邮件,但许多功能仍在开发中。API 可能会更改。
目前仅支持 SwiftPM。
要添加包,只需在 Xcode 中选择 File
/ Add Packages...
并将此 URL 粘贴到搜索/URL 框中:https://github.com/aronbudinszky/postmark-swift
。
由于 PostmarkSwift 使用了新的 async/await API,因此至少需要 iOS 13 或 macOS 12。
// Create client and send
let client = PostmarkSwift.Client(serverToken: "your-server-token")
// Create an email message
let message = PostmarkSwift.OutgoingEmail(
from: "you@yourcompany.com",
to: "user@example.com",
subject: "Hello",
textBody: "World!"
)
// Send it and report the results
let result = try await client.send(message)
print("Message was submitted for sending at \(result.submittedAt) to recipient(s) \(result.to) with ID \(result.messageID)")
如果您的请求出现任何问题,当您尝试发送时会抛出相应的错误。
您也可以发送 HTML 消息,如下所示
// Create an email message
let message = PostmarkSwift.OutgoingEmail(
from: "you@yourcompany.com",
to: "user@example.com",
subject: "Hello",
textBody: "World!",
htmlBody: "<strong>World!</strong>"
)