I´m trying to send mail from my iOS app with Mailgun
and Alarmofire
I found this piece of code but Xcode
generates error:
Cannot convert value of type '[String : String]' to expected argument type 'HTTPHeaders?'
Code:
let parameters = [
"from": "[email protected]",
"to": "[email protected]",
"subject": "Subject of the email",
"text": "This is the body of the email."]
let header = [
"Authorization": "Basic MY-API-KEY",
"Content-Type" : "application/x-www-form-urlencoded"]
let url = "https://api.mailgun.net/v3/MY-DOMAIN/messages"
Alamofire.request(url,
method: .post,
parameters: parameters,
encoding: URLEncoding.default,
headers: header)
.responseJSON { response in
print("Response: \(response)")
}
Any suggestions?
You need to set the type explicitly.
let headers : HTTPHeaders = [
"Authorization": "Basic MY-API-KEY",
"Content-Type" : "application/x-www-form-urlencoded"
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With