【问题标题】:IOS Swift Mailgun not sending emailIOS Swift Mailgun不发送电子邮件
【发布时间】:2017-12-23 13:24:43
【问题描述】:

我正在尝试使用带有 Swift 的 MailGun api 发送电子邮件。我使用 mailgun 创建并激活了免费帐户。安装的吊舱。

cocoapods mailgun pod

如果我按下按钮,我会收到“电子邮件已发送”消息,但我没有收到这封电子邮件,它也不会显示在 mailgun“日志”或“报告”中。

我还添加并验证了我的个人电子邮件到“授权收件人”

我绑在IOS模拟器和实际设备上运行没有运气。

   @IBAction func dddd(_ sender: Any) {

    let mailgun = MailgunAPI(apiKey: "key-<my_key from mailgun>, clientDomain: "sandboxe437***********.mailgun.org")

    mailgun.sendEmail(to: "me@mail.com", from: "Test User <myemail@mail.com", subject: "This is a test15", bodyHTML: "<b>test<b>") { mailgunResult in

        if mailgunResult.success{
            print("Email was sent")
        }else{
            print("error")
        }

}

有什么建议我错过了什么?

谢谢,

追猎者

【问题讨论】:

    标签: ios swift mailgun


    【解决方案1】:

    @Stalker,您的from 参数没有结束&gt;。我希望你已经看到了。 如果你已经在使用 Alamofire 来处理你的网络请求,那么不需要这个额外的依赖 mailgun pod:

    斯威夫特 3.2

     import Alamofire
        
        let parameters = [
                       "from": "sender@whatyouwant.com",
                         "to": "anyRecipient@example.com",
                    "subject": "Subject of the email",
                       "text": "This is the body of the email."]
        let header = [
                "Authorization": "Basic YOUR-BASE64ENCODED-KEY",
                "Content-Type" : "application/x-www-form-urlencoded"]
    
        let url = "https://api.mailgun.net/v3/YOUR-DOMAIN/messages"
        Alamofire.request(url,
                       method: .post,
                   parameters: parameters,
                     encoding: URLEncoding.default,
                      headers: header)
                .responseJSON { response in
                    print("Response: \(response)")
                    }
    

    在标题中,您必须将 YOUR-BASE64ENCODED-KEY 替换为“API:YOUR-SECRET-API-KEY”的 base64 编码字符串,其中 YOUR-SECRET-API-KEY 位于 Mailgun 仪表板上。

    在 URL 中,您还可以将 YOUR-DOMAIN 替换为您的 Mailgun 域。

    这样你就可以通过 Mailgun 发送电子邮件了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-10-01
      • 1970-01-01
      • 2015-06-20
      • 2017-10-12
      • 2018-12-05
      • 1970-01-01
      • 2017-04-30
      相关资源
      最近更新 更多