8个步骤即可从0开始创建一个邮件发送App
创建目录:
mkdir mailBox cd mailBox
swift package初始化, 生成Package.swift 等文件
swift package init
编辑Package.swift,导入依赖, 瞄神最新发布的一个库, 如下:
import PackageDescription
let package = Package(
name: "mailBox",
dependencies: [
.Package(url: "https://github.com/onevcat/Hedwig.git",
majorVersion: 1)
]
)
下载依赖并生成mailBox.xcodeproj:
swift package generate-xcodeproj
编译依赖,生成相应静态库:
swift build
打开mailBox.xcodeproj, 新建 target -> Single View Application: 取名为mailbox
在该target的Build Phases->Link Binary With Libraries中 添加
Hedwig.framework
在代码中
import Hedwig
, 就可以愉快的书写逻辑代码了,
阿里云企业邮箱范例如下:
let hed = Hedwig.init(hostName: "smtp.mxhichina.com", user: "xx@xxx.cn", password: "xxx", port: 465, secure: .ssl)
let mail = Mail(text:"haha", from: "xx@xxx.cn", to: "yyy@qq.com", subject: "hello")
hed.send(mail){
err in
if let err = err{
print(err.localizedDescription)
}
}
finally, 更加详细的使用请参考:https://github.com/onevcat/hedwig