django下如何使用mailgun的服务?


新项目,计划测试下mailgun的邮件服务。已经成功注册了mailgun的帐号。请问的django这边该如何配置?谢谢

开发 邮件 django mailgun 邮件服务

色东法夫撒 10 years, 5 months ago
  1. 在MailGun注册;
  2. 按提示配置DNS信息(有点多);
  3. 登录后,在mailgun的控制台页面(https://mailgun.com/cp),点击你的域名,查看邮件的登录信息;
  4. 打开django的settings.py进行配置。如下:

    EMAIL_USE_TLS = True
    EMAIL_HOST = 'smtp.mailgun.org'
    EMAIL_HOST_USER = '[email protected]'
    EMAIL_HOST_PASSWORD = 'SOMEPASSWORD'
    EMAIL_PORT = 587
    
  5. 测试

    ./manage.py shell
    >>> from django.core.mail import send_mail
    >>> send_mail('MailGun works great!', 'It really really does.', '[email protected]', ['[email protected]'], fail_silently=False)
    
精肛互撸娃 answered 10 years, 5 months ago

也可以使用 django-mailgun, https://github.com/bradwhittington/dj...

  1. 安装django-mailgun

    pip install django-mailgun
    
  2. 将下列配置添加到settings.py中

    EMAIL_BACKEND = 'django_mailgun.MailgunBackend'
    MAILGUN_ACCESS_KEY = 'ACCESS-KEY'
    MAILGUN_SERVER_NAME = 'SERVER-NAME'
    
高达不萝莉 answered 10 years, 5 months ago

Your Answer