首先,添加 SMTPKitten 依赖项

.package(url: "https://github.com/joannis/SMTPKitten.git", from: "1.0.0"),

然后将其作为你的目标的依赖项添加

.product(name: "SMTPKitten", package: "SMTPKitten"),

创建连接

try await SMTPClient.withConnection(
    to: "localhost",
    port: 1025,
    ssl: .insecure
) { client in
    // 1. Authenticate
    try await client.login(
        user: "xxxxxx",
        password: "hunter2"
    )
    
    // 2. Send emails
}

发送邮件

在发送邮件之前,首先创建一个 Mail 对象。 然后,在客户端调用 sendMail

let mail = Mail(
    from: MailUser(name: "My Mailer", email: "noreply@example.com"),
    to: [MailUser(name: "John Doe", email: "john.doe@example.com")],
    subject: "Welcome to our app!",
    content: .plain("Welcome to our app, you're all set up & stuff.")
)

try await client.sendMail(mail)

Mail.Content 类型支持各种其他类型的信息,包括 HTML、Alternative(HTML 带有纯文本回退)和 multipart。

社区

加入我们的 Discord,提出任何问题并进行友好的交流。

如果您需要在您的项目上获得实践支持,我们的团队可以通过 hello@unbeatable.software 与我们联系。