ThirdPartyMailer

与第三方 iOS 邮件客户端交互,使用自定义 URL Schemes。

Platform iOS Swift 5 Build Swift Package Manager CocoaPods compatible Carthage Compatible MIT license

支持的邮件客户端

客户端 URL Scheme App Store
Gmail googlegmail 链接
Spark readdle-spark 链接
Airmail airmail 链接
Microsoft Outlook ms-outlook 链接
Yahoo Mail ymail 链接
Fastmail fastmail 链接
Proton Mail protonmail 链接
Sparrow sparrow 已停止维护
Dispatch x-dispatch 已停止维护

遗憾的是,并非所有邮件客户端都提供 URL schemes 以供 ThirdPartyMailer 支持。如果您知道其他可支持的客户端,请告知我们

如何安装

Swift Package Manager

在 Xcode 中,点击 “File” 菜单, “Swift Packages”, “Add Package Dependency…”,然后输入此仓库的 URL:https://github.com/vtourraine/ThirdPartyMailer.git

CocoaPods

使用 CocoaPods,只需将 ThirdPartyMailer 添加到您的 Podfile

pod 'ThirdPartyMailer'

或者,您可以手动从 Sources 文件夹导入文件。

如何使用

获取支持的客户端列表

let clients = ThirdPartyMailClient.clients

测试客户端的可用性(即应用程序是否已安装)

⚠️为了测试客户端的可用性,您的应用程序需要在其 Info.plist 文件中声明相关的 URL scheme,通过添加 LSApplicationQueriesSchemes 数组。您可以在此处找到示例,或查看文档

if ThirdPartyMailer.isMailClientAvailable(client) {
    // ...
}

打开客户端(可选择添加消息接收者、主题、正文、抄送和密送)

ThirdPartyMailer.openCompose(client, recipient: "friend@mail.com")

ThirdPartyMailer.openCompose(client, recipient: "friend@mail.com", subject: "Hello", body: "Good morning…", cc: "cc@mail.com", bcc: "bcc@mail.com")

🆕 使用系统默认邮件客户端

如果您未指定客户端,openCompose(…) 函数将使用 .systemDefault,这是一个为标准 mailto: scheme 定义的客户端。默认情况下,它将打开 Apple Mail,但如果用户选择了自定义邮件客户端 (iOS 14),它将自动打开该客户端。

ThirdPartyMailer.openCompose(recipient: "friend@mail.com")

系统要求

ThirdPartyMailer 使用 Swift 5.0 编写,需要 iOS 10.0 及以上版本,Xcode 10.2 及以上版本。

贡献者

ThirdPartyMailer 由 Vincent Tourraine 创建。

许可证

ThirdPartyMailer 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE.txt 文件。