iOS开发:通过swift package创建邮件客户端

8个步骤即可从0开始创建一个邮件发送App

  1. 创建目录:
    mkdir mailBox cd mailBox

  2. swift package初始化, 生成Package.swift 等文件
    swift package init

  3. 编辑Package.swift,导入依赖, 瞄神最新发布的一个库, 如下:

import PackageDescription
let package = Package(
    name: "mailBox",
    dependencies: [
        .Package(url: "https://github.com/onevcat/Hedwig.git",
                 majorVersion: 1)
    ]
)
  1. 下载依赖并生成mailBox.xcodeproj:
    swift package generate-xcodeproj

  2. 编译依赖,生成相应静态库:
    swift build

  3. 打开mailBox.xcodeproj, 新建 target -> Single View Application: 取名为mailbox

  4. 在该target的Build Phases->Link Binary With Libraries中 添加Hedwig.framework

  5. 在代码中import Hedwig, 就可以愉快的书写逻辑代码了,
    阿里云企业邮箱范例如下:

let hed = Hedwig.init(hostName: "smtp.mxhichina.com", user: "[email protected]", password: "xxx", port: 465, secure: .ssl)

       let mail = Mail(text:"haha", from: "[email protected]", to: "[email protected]", subject: "hello")
       hed.send(mail){
           err in
           if let err = err{
               print(err.localizedDescription)
           }
       }

finally, 更加详细的使用请参考:https://github.com/onevcat/hedwig

你可能感兴趣的:(iOS开发:通过swift package创建邮件客户端)