0
私はMailgunを使用して電子メールを送信するコードを持っていますが、電子メールが正常に送信されたという応答コード200が返ってきます。いずれかを表示する。Swift - Mailgun - 電子メールを受信しない
以下私のコードです:私はそれを下に、データ変数にいくつかの微調整を行うことにより、作業しまった
func email() {
let session = URLSession.shared
let request = NSMutableURLRequest(url: NSURL(string: "https://api.mailgun.net/v3/sandboxBLAHBLAH.mailgun.org")! as URL)
request.httpMethod = "POST"
let credentials = "api:key-BLAHBLAH"
request.setValue("Basic \(credentials.toBase64())", forHTTPHeaderField: "Authorization")
let data = "from:Test<([email protected])>&to:[[email protected],([email protected])]&subject:Hello&text:Testing_email"
request.httpBody = data.data(using: String.Encoding.ascii)
let task = session.dataTask(with: request as URLRequest, completionHandler: {(data, response, error) in
if let error = error {
print(error)
}
if let response = response {
print("url = \(response.url!)")
print("response = \(response)")
let httpResponse = response as! HTTPURLResponse
print("response code = \(httpResponse.statusCode)")
}
})
task.resume()
}
extension String {
func fromBase64() -> String? {
guard let data = Data(base64Encoded: self) else {
return nil
}
return String(data: data, encoding: .utf8)
}
func toBase64() -> String {
return Data(self.utf8).base64EncodedString()
}
}