2

I am trying to send email from iOS app to Mailjet server. All going fine, i'm get OK response from server but nothing happened, - zero email in my box. Here is my code. Thank you!

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()
}

Server response: -

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

} })

Any suggestions?

  • What do you get as `response` and `data` back from the Web service? Maybe they contain some additional info. – dr_barto Jan 26 '18 at 16:34
  • @dr_barto I am updated question – Maxim Poltoratsky Jan 26 '18 at 17:09
  • Ok no hints there... I haven't used Mailjet, but if it's similar to Mailgun (the service I'm using) there should be a dashboard showing you all send requests and the status of the sent mails. Maybe this can help you to find out what's going on. – dr_barto Jan 26 '18 at 17:27

1 Answers1

0

with a Free Tier account you will have a daily limit of 200 mails. (you can check by clicking on your profile at the right top) If you reached that the api call will still be able to be successful but mailjet will not proceed any further. Meaning that you will also not see any kind of message in your dashboard.

phauck
  • 1
  • 1