Raulsc
Raulsc

Reputation: 75

Send email on GAE using Django module (django.core.mail)

Before the migration of my app to GAE, I was using the following code to send emails and it worked pretty good:

from django.core.mail import send_mail

subject = 'Hello!'
msg = '\n \n Hello World!'
sender = settings.DEFAULT_FROM_EMAIL
to = ['[email protected]']

send_mail(subject,msg,sender,to,fail_silently=False)

Now, after the migration to GAE (on Python 2.7) it doesn't work. It just throw the following error:

Exception Type: NotImplementedError
Exception Location: C:\Program Files(x86)\Google\google_appengine\google\appengine\api\remote_socket\_remote_socket.py in gethostbyaddr, line 256

I have the settings.py file configured as follo

EMAIL_USE_TLS = True
EMAIL_HOST = 'xxx.yyy.com'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'zzzzzzzzz'
EMAIL_PORT = 587

Does anyone send e-mails with Django module on GAE and know something about that error?

Upvotes: 0

Views: 1110

Answers (2)

Lipis
Lipis

Reputation: 21835

If you want to send emails from AppEngine, you should use the mail.send_mail():

from google.appengine.api import mail

mail.send_mail(sender="Example.com Support <[email protected]>",
              to="Albert Johnson <[email protected]>",
              subject="Your account has been approved",
              body="Hello, world!")

Upvotes: 3

Raulsc
Raulsc

Reputation: 75

I fugured out the problem why apeeared that error:

Django send_mail is not supported on GAE. It's necessary to add a Django e-mail backend in our app to allow it be executed on GAE.

Two steps to do:

  1. Import third-party modul --> appengine_emailbackend

  2. Write down one of the following lines on your settings.py file:

    EMAIL_BACKEND = 'appengine_emailbackend.async.EmailBackend'

    EMAIL_BACKEND = 'appengine_emailbackend.EmailBackend'

Even so, after use that backend it's not throwing any error, but it doesn't send anything.

Anybody could help?

Upvotes: -1

Related Questions