python - 使用 Mailgun API 通过 Python 发送电子邮件

标签 python email mailgun

我尝试使用 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.orgYOUR_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/

相关文章:

python - Rmarkdown 是否允许编织 matplotlib 绘图?如果是这样,你能帮我解决问题吗?

python - m2m 字段上的 post_save 信号

windows - 在 Azure 上托管电子邮件

python - 如何使用 Mailgun 发送带有多个附件和自定义文件名的邮件(来自 Python)

python - 如何加载特定的 Excel 工作表?

python - 如何使用Delegate控制QTableView的行高

ruby-on-rails - 在 Rails 中验证多封电子邮件和处理错误的最佳方式是什么?

html - HTML 中的 Interop.Outlook 消息显示为纯文本

php - 如何使用 mailgun 批量发送带附件的邮件?

mailgun - Mailgun 中已处理电子邮件数量的 API