The http api provided by mailgun can be directly called through python. If it is combined with Django, only mailgun 0.2 needs to be set as follows:
Add the following to setting. py:
EMAIL_BACKEND = 'django_mailgun.MailgunBackend'MAILGUN_ACCESS_KEY = 'ACCESS-KEY'#your mailgun api keyMAILGUN_SERVER_NAME = 'SERVER-NAME'#your mailgun domain
After configuration, you can use send_mail to send emails. However, this version has bugs and does not support group sending, mainly because _ init _ in django_mailgun __. the _ Send () function of Py is as follows:
try: r = requests.\ post(self._api_url + "messages.mime", auth=("api", self._access_key), data={ "to": recipients, "from": from_email, }, files={ "message": StringIO(email_message.message().as_string()) } ) except: if not self.fail_silently: raise return False
Here, the mime request is used. mailgun only processes the last email of the recipients. Therefore, you cannot send a group of emails. Instead, try to send an HTML message:
try: r = requests.\ post(self._api_url + "messages", auth=("api", self._access_key), data={ "to": recipients, "from": from_email, "subject":subject,#subject = unicode(email_message.message()['Subject']) "html":text,#text = email_message.body }, ) except: if not self.fail_silently: raise return False
In this way, the group can be sent.
Modify ___ init _. py and then re-setup Django-mailgun,
python2.6 setup.py buildpython2.6 setup.py install
If an error is reported during install, you need to find the django_mailgun-0.2-py2.6.egg after RM
Restart Django to run it.