使用Mailjet发送电子邮件不起作用,但状态代码为200

时间:2018-01-26 14:52:38

标签: ios swift email smtp mailjet

我正在尝试从iOS应用程序向Mailjet服务器发送电子邮件。一切顺利,我收到了来自服务器的响应,但没有任何反应, - 我的邮箱中没有电子邮件。这是我的代码。谢谢!

func sendEmail() {

    var recipients = [[String: Any]]()
    recipients.append(["Email": "maxim.poltoratsky@pinta.com.ua"])

    let body: [String: Any] = [
        "FromEmail": "ruslan@pinta.com.ua",
        "FromName": "Me",
        "Subject": "YEEES",
        "Text-part": "Greetings from IOS ;)",
        "Recipients": recipients
    ]

    let url = URL(string: "https://in-v3.mailjet.com")
    var request = URLRequest(url: url!)

    let username = "MY_SECRET_KEY"
    let password = "MY_API_KEY"
    let loginString = "\(username):\(password)"

    guard let loginData = loginString.data(using: String.Encoding.utf8) else {
        return
    }
    let base64LoginString = loginData.base64EncodedString()

    request.httpMethod = "POST"
    request.setValue("application/json", forHTTPHeaderField: "Content-Type")
    request.setValue("Basic \(base64LoginString)", forHTTPHeaderField: "Authorization")

    do {
        request.httpBody = try JSONSerialization.data(withJSONObject: body, options: [])
    }
    catch {
        print("error during JSON serialization")
        dump(error)
        return
    }

    let session = URLSession.shared
    let task = session.dataTask(with: request, completionHandler: { (data, response, error) in
        print(error)
        print(response)
        print(data)
    })
    task.resume()
}

服务器响应: -

{ URL: https://in-v3.mailjet.com/ } { Status Code: 200, Headers {
Date =     (
    "26 Jan 2018 19:05:25 +0200"
);
"Max-Age" =     (
    0
);

}})

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

使用免费层级帐户,您每天可以收到 200 封邮件。 (您可以通过单击右上角的个人资料进行检查)如果您达到该 api 调用仍然能够成功,但 mailjet 将不会继续进行。这意味着您也不会在仪表板中看到任何类型的消息。