Pythonanywhere 出现 Mailgun 404 错误

Mailgun 404 error with Pythonanywhere

我正在尝试在托管在 Pythonanywhere 上的 Django 项目中使用 mailgun。

在我的 WSGI 文件中,我有:

os.environ['DJANGO_MAILGUN_SERVER_NAME'] = 'https://api.mailgun.net/v3/sandboxnumbersomething.mailgun.org/messages'
os.environ['DJANGO_MAILGUN_API_KEY'] ='mykey'

我的设置是:

# EMAIL
# ------------------------------------------------------------------------------
DEFAULT_FROM_EMAIL = env('DJANGO_DEFAULT_FROM_EMAIL',
                         default='Apitrak <noreply@apitrak.com>')
EMAIL_BACKEND = 'django_mailgun.MailgunBackend'
MAILGUN_ACCESS_KEY = env('DJANGO_MAILGUN_API_KEY')
MAILGUN_SERVER_NAME = env('DJANGO_MAILGUN_SERVER_NAME')

当我的应用触发电子邮件时(例如在注册时),我遇到 404 错误:

MailgunAPIError at /accounts/email/

<Response [404]>

Request Method:     POST
Request URL:    https://vincentle.pythonanywhere.com/accounts/email/
Django Version:     1.8.6
Exception Type:     MailgunAPIError
Exception Value:    

<Response [404]>

Exception Location:     /home/vincentle/.virtualenvs/apitrak/lib/python3.4/site-packages/django_mailgun.py in _send, line 154
Python Executable:  /usr/local/bin/uwsgi
Python Version:     3.4.0
Python Path:    

['/var/www',
 '.',
 '',
 '/var/www',
 '/home/vincentle/.virtualenvs/apitrak/lib/python3.4',
 '/home/vincentle/.virtualenvs/apitrak/lib/python3.4/plat-x86_64-linux-gnu',
 '/home/vincentle/.virtualenvs/apitrak/lib/python3.4/lib-dynload',
 '/usr/lib/python3.4',
 '/usr/lib/python3.4/plat-x86_64-linux-gnu',
 '/home/vincentle/.virtualenvs/apitrak/lib/python3.4/site-packages',
 '/home/vincentle/apitrak']

Server time:    Tue, 17 Nov 2015 16:02:28 +0100

我已经尝试在我的 WebApp 的 virtualenv 中卷曲:

curl -s --user 'api:key-NUMBERS' https://api.mailgun.net/v3/NUMBERS.mailgun.org/messages -F from='Excited User <excited@samples.mailgun.org>' -F to='vincent@vincentle.fr'  -F subject='Hello'  -F text='Testing some Mailgun awesomeness!'

这工作正常。

设置DJANGO_MAILGUN_SERVER_NAME应该是域名,而不是url。

尝试以下操作:

os.environ['DJANGO_MAILGUN_SERVER_NAME'] = '<sandboxnumbersomething>.mailgun.org'

来自readme

Replace SERVER-NAME with the last part of your "API Base URL" (e.g. https://api.mailgun.net/v3/<your_server_name>), also found in your Mailgun account details.