VaporResend

Vapor Logo Swift 5.10 Logo MIT License

VaporResendSwiftResend 包的封装器,专为与 Vapor 框架一起使用而设计,用于与 Resend 电子邮件发送平台 API 进行通信。

设置

添加依赖

将依赖项添加到您的 Package.swift 文件中

dependencies: [
	...
	.package(url: "https://github.com/hsharghi/vapor-resend.git", from: "1.0.0")
],
targets: [
    .target(name: "App", dependencies: [
        .product(name: "VaporResend", package: "vapor-resend"),
    ]),

配置环境变量

提供 RESEND_API_KEY 环境变量以进行身份验证。

用法

发送电子邮件

导入 VaporResend 模块并配置您的路由

import Vapor
import VaporResend

func routes(_ app: Application) throws {
    app.get("send") { req async throws -> String in
        let id = try await req.resend.emails.send(email: .init(from: .init(email: "hadi@domain.com", name: "Hadi"),
                                            to: ["john@apple.com"],
                                            subject: "Sending email from Vapor",
                                           text: "Email sent using ResendVapor"))
        
        return id
    }
}

有关完整的 SDK 文档,请查看 SwiftResend 包。

许可证

此软件包在 MIT 许可证下发布。 有关详细信息,请参阅 LICENSE