Mail Gun电子邮件无法在Google App Engine上的烧瓶中运行

时间:2019-06-06 22:00:41

标签: python-3.x google-app-engine google-cloud-platform python-requests app-engine-flexible

我正在尝试从Google App Engine上的烧瓶应用程序发送自动mailgun电子邮件。当我在本地运行时,它工作正常。但是,即使它没有错误运行,也不会发送电子邮件。

代码如下:

def send_simple_message(text):
    url = 'https://api.mailgun.net/v3/{}/messages'.format('')
    auth = ('api', '3822ba6d2b1ad202e83a4322a80c7600-87cdd773-683e02b1')
    data = {
        'from': 'Mailgun User <mailgun@{}>'.format('sandboxf04ggge3c1dc36e527c92f3a967e7f7c.mailgun.org'),
        'to': 'example@gmail.com',
        'subject': 'Simple Mailgun Example',
        'text': text
    }

    response = requests.post(url, auth=auth, data=data)
    response.raise_for_status()

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

我对malign api不熟悉,但是看文档中的示例,我认为您忘记将域添加到url:

def send_simple_message(text):
    url = 'https://api.mailgun.net/v3/{}/messages'.format('sandboxf04ggge3c1dc36e527c92f3a967e7f7c.mailgun.org')
    auth = ('api', '3822ba6d2b1ad202e83a4322a80c7600-87cdd773-683e02b1')
    data = {
        'from': 'Mailgun User <mailgun@{}>'.format('sandboxf04ggge3c1dc36e527c92f3a967e7f7c.mailgun.org'),
        'to': 'example@gmail.com',
        'subject': 'Simple Mailgun Example',
        'text': text
    }

response = requests.post(url, auth=auth, data=data)
response.raise_for_status()