0

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 = ['xx@xx.com']

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 = 'my.account@yy.com'
EMAIL_HOST_PASSWORD = 'zzzzzzzzz'
EMAIL_PORT = 587

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

Lipis
  • 21,388
  • 20
  • 94
  • 121
Raulsc
  • 75
  • 2
  • 12

2 Answers2

3

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 <support@example.com>",
              to="Albert Johnson <Albert.Johnson@example.com>",
              subject="Your account has been approved",
              body="Hello, world!")
Lipis
  • 21,388
  • 20
  • 94
  • 121
  • It's another option @Lipis (directly with the api from google appengine or using the third-party appengine_emailbackend). I figured out this problem. But now I'm with another one: trying to redirect google mailer to my personal mailer (I want that the e-mail will be sent with an address like : my_email@mydomain.com). I saw something related with that [here](http://stackoverflow.com/questions/7339932/send-mail-from-a-different-domain-in-google-app-engine). Do you know how to do it? – Raulsc Feb 19 '13 at 10:37
  • @Raulsc if you read in the documentation, the sender should be an admin of your application, and you could connect your GAE app to your custom domain to be able to add the my_email@mydomain.com to the list of the admins. Sounds scary but eventually you will have to have a custom domain for your app and that's how you should do it. – Lipis Feb 19 '13 at 10:41
  • @Raulsc You should read how you can connect your application with a custom domain (it's by using Google Apps) – Lipis Feb 19 '13 at 10:42
-1

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?

Raulsc
  • 75
  • 2
  • 12
  • I figured out the problem: when django app is migrated to GAE, it's not possible to use a mailer different than Google. When I tried send an e-mail using another mailer, send_mail function thew me an error: "Unauthorized sender". So, sorry guys, but right know we just can send e-mails using a gmail account. – Raulsc Feb 19 '13 at 09:12