[英]IOS Swift Mailgun not sending email
I am trying to send Email using MailGun api with Swift. 我正在尝试使用Swift使用MailGun api发送电子邮件。 I created and activate free account with mailgun.
我使用mailgun创建并激活了免费帐户。 Installed pod.
已安装的吊舱。
cocoapods mailgun pod cocoapods mailgun pod
If I press button I am getting message "Email was sent" but I am not receiving this email, nor it is displays in mailgun "Logs" or "Reporting". 如果我按下按钮我收到消息“电子邮件已发送”,但我没有收到此电子邮件,也没有显示在mailgun“日志”或“报告”中。
I have also added and verified my personal e-mail to "Authorized Recipients" 我还添加并验证了我的个人电子邮件给“授权收件人”
I tied to run on IOS simulator and actual devices no luck. 我绑在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")
}
}
Any word of advise what did I missed? 有什么建议我错过了什么?
Thank you, 谢谢,
Stalker 潜行者
@Stalker, your from
parameter does not have a closing >
. @Stalker,你的
from
参数没有结束>
。 I hope you have seen it. 我希望你见过它。 If you are already using Alamofire for your network requests then no need for this extra dependency
mailgun pod
: 如果您已经在使用Alamofire进行网络请求,则不需要这个额外的依赖性
mailgun pod
:
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)")
}
In the header, you have to replace YOUR-BASE64ENCODED-KEY
with the base64 encoded string of "API:YOUR-SECRET-API-KEY" where YOUR-SECRET-API-KEY
is found on your Mailgun dashboard. 在标题中,您必须使用base64编码的“API:YOUR-SECRET-API-KEY”字符串替换
YOUR-BASE64ENCODED-KEY
,其中在您的Mailgun仪表板上找到了YOUR-SECRET-API-KEY
。
In the URL you also replace YOUR-DOMAIN
with your Mailgun domain. 在URL中,您还将
YOUR-DOMAIN
替换为您的Mailgun域。
With that you should be good to go and send emails through Mailgun. 有了它你应该很高兴去通过Mailgun发送电子邮件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.