Search code examples
djangogoogle-app-enginedjangoappenginedjango-mailer

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?


Solution

  • 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!")