SWMailgun 1.0.8

SWMailgun 1.0.8

John Lima 维护。



SWMailgun 1.0.8

SWMailgun


SWMailgun 在您使用 Mailgun 发送电子邮件的 iOS 应用时提供了一个简单的替代方案。

为什么

有时,您可能需要在 iOS 应用中设置简单的电子邮件表单,或者在执行某个操作后触发电子邮件而无需设置自己的服务,有时您可能不想使用 MailComposeViewControllerSMTP 库。当您需要使用 iOS 应用发送电子邮件时,这是一个简单的替代方案。

✉️Emailgun

Emailgun 为交易电子邮件提供了一个简单的可靠 API。您需要一个 ApiKey 和一个帐户来使用客户端。

❗️要求

  • iOS 9.3+
  • Swift 5.0+

安装

Swift Package Manager

SWMailgun 通过 SPM 提供。要安装它,按照以下步骤操作

Open Xcode project > File > Swift Packages > Add Package Dependecy

之后,在字段中填入 URL: https://github.com/thejohnlima/SWMailgun.git

CocoaPods

SWMailgun 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中

pod 'SWMailgun'

然后运行 pod install

🎓如何使用

用法非常简单

// MARK: - Example using html string

import SWMailgun

let service = MailgunService()
let html = "<b>Test</b>"

let email = MailgunEmail(
    from: "Excited User <[email protected]>",
    to: "[email protected]",
    subject: "This is a test",
    html: html
)

let auth = MailgunAuth(
    domain: "YOUR_DOMAIN",
    apiKey: "YOUR_API_KEY"
)

service.send(email: email, auth: auth) { result, error in
    guard let result = result else {
        print("Error: \(error)")
        return
    }
    print("Email was sent: \(result.isSent())")
}
// MARK: - Example using html template
// You can create your html template in Mailgun web site

import SWMailgun

let service = MailgunService()
let parameters = ["user_name": "John", "temporary_password": "johnjohn123"]

guard let variables = try? JSONSerialization.data(withJSONObject: [parameters], options: .prettyPrinted) else {
    print("❌ Something wrong. Check your parameters")
    return
}

let email = MailgunEmail(
    from: "Excited User <[email protected]>",
    to: "[email protected]",
    subject: "This is a test",
    template: "forgot_password",
    variables: variables
)

let auth = MailgunAuth(
    domain: "YOUR_DOMAIN",
    apiKey: "YOUR_API_KEY"
)

service.send(email: email, auth: auth) { result, error in
    guard let result = result else {
        print("Error: \(error)")
        return
    }
    print("Email was sent: \(result.isSent())")
}

需要更多示例,请打开 demo 项目

🙋🏻‍♂️ 通信

  • 如果你发现了一个错误,请提交一个问题。
  • 如果你有一个功能请求,请提交一个问题。
  • 如果你想贡献,请提交一个分支请求。 👨🏻‍💻

📜许可证

SWMailgun 采用 MIT 许可证。有关更多信息,请参阅 LICENSE 文件。