将此库添加到 Package.swift
.package(url: "https://github.com/Joannis/VaporSMTPKit.git", from: "1.0.0")
将目标 "VaporSMTPKit"
添加到你自己的目标的依赖项中。 在 Swift 5.2 清单中,它看起来像这样:
.product(name: "VaporSMTPKit", package: "VaporSMTPKit"),
import VaporSMTPKit
extension SMTPCredentials {
static var `default`: SMTPCredentials {
return SMTPCredentials(
hostname: "smtp.example.com",
ssl: .startTLS(configuration: .default),
email: "noreply@example.com",
password: "<SECRET>"
)
}
}
app.get { request -> EventLoopFuture<String> in
let email = Mail(
from: "noreply@example.com",
to: [
MailUser(name: "Myself", email: "me@example.com")
],
subject: "Your new mail server!",
contentType: .plain,
text: "You've set up mail!"
)
return request.application.sendMail(email, withCredentials: .default).map {
return "Check your mail!"
}
}