我尝试使用 Mailgun 通过 python 发送电子邮件
我有
def send_simple_message():
return requests.post(
"https://api.mailgun.net/v3/sandbox6247218655a94010b9840c23c2688fc7.mailgun.org",
auth=("api", "key-********"),
data={"from": "Excited User <bb@gmail.com>",
"to": ["bb@outlook.com", "bb4@gmail.com"],
"subject": "Hello",
"text": "Testing some Mailgun awesomness!"})
我意识到我忘记了 /messages
def send_simple_message():
return requests.post(
"https://api.mailgun.net/v3/sandbox6247218655a94010b9840c23c2688fc7.mailgun.org/messages",
auth=("api", "key-********"),
data={"from": "Excited User <bb@gmail.com>",
"to": ["bb@outlook.com", "bb4@gmail.com"],
"subject": "Hello",
"text": "Testing some Mailgun awesomness!"})
我运行它
python mail.py
我仍然没有看到任何电子邮件。 我还检查了我的 MailGun 和垃圾邮件文件夹。
对我有什么提示吗?
最佳答案
根据MailGun documentation ,在这里你可以看到 POST url 应该是这种格式 https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages
从您的代码中,我可以看到 sandbox6247218655a94010b9840c23c2688fc7.mailgun.org
是 YOUR_DOMAIN_NAME
但您缺少格式,即 /messages
API 端点。
因此,您所要做的就是将 /messages
端点添加到您的帖子 URL。所以它从 https://api.mailgun.net/v3/sandbox6247218655a94010b9840c23c2688fc7.mailgun.org
更改为 https://api.mailgun.net/v3/sandbox6247218655a94010b9840c23c2688fc7.mailgun.org/消息
。
关于python - 使用 Mailgun API 通过 Python 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53861582/