Sending email from an web2py on GAE
Asked Answered
K

3

5

I am trying to send a mail from my web2py app hosted on GoogleAppEngine. But it is not working. I used the mail function that was given with the web2py. Does anybody how to do this? I read in the GAE Documentation that python mail library would not work with GAE and GAE mail library has to be used. Does it also applies to web2py mail? Thanks

Kaffiyeh answered 16/4, 2010 at 20:56 Comment(2)
When you say "not working" what do you mean exactly? Is it giving you some error message? This page doesn't seem confident that email will work with web2py + App Engine: wiki.web2py.com/…Renaldo
Email is not getting sent, and I get the following error I am getting the following error. Mail.send failure:'module' object has no attribute 'getaddrinfo'Kaffiyeh
S
5

The web2py gluon.tools.Mail class (that is used by the Auth module too) works on GAE and non-GAE out of the box. You just need to pass the correct settings:

mail=Mail()
mail.settings.server="smtp.example.com:25" or "gae"
mail.settings.sender="[email protected]"
mail.settings.tls=True or False
mail.settings.login="you:password"

It supports multiple encodings, MIME and attachments.

Stave answered 17/4, 2010 at 0:53 Comment(2)
I am getting the following error. Mail.send failure:'module' object has no attribute 'getaddrinfo' and the code for the mail part is mail = Mail() mail.settings.server = 'smtp.gmail.com:587' mail.settings.login = 'username:passwordxperia x1' mail.settings.sender = '[email protected]' mail.settings.tls = True or False mail.send(to,subject,message) Above code works when I use from my local machine but does not once I upload to the GAEKaffiyeh
I missed something in my comment above and I corrected it. It is true that you have to have the GAE API and it is true that web2py provides an abstraction layer. But you cannot connect to an external server because smtplib requires socket and socket is not available on GAE. Bottom line you have to set mail.settings.server="gae"Stave
C
3

The web2py gluon.tools.Mail class works on GAE. See code snippet gluon.tools line 310

    try:
        if self.settings.server == 'gae':
            from google.appengine.api import mail
            result = mail.send_mail(sender=self.settings.sender, to=to,
                                    subject=subject, body=text)

This is the correct settings to work on GAE

mail=Mail()
mail.settings.server="gae"
mail.settings.sender="[email protected]" #This must be the email address of a registered
                                       #administrator for the application, or the address 
                                       #of the current signed-in user. 
mail.settings.login="you:password"

See http://code.google.com/intl/en/appengine/docs/python/mail/emailmessagefields.html sender The email address of the sender, the From address. This must be the email address of a registered administrator for the application, or the address of the current signed-in user. Administrators can be added to an application using the Administration Console. The current user's email address can be determined with the Users API.

Sorry! My english is very poor. I hope to help.

Celso Godinho ([email protected]) Brazil World Cup champion soccer 2010

Canzona answered 27/4, 2010 at 22:47 Comment(0)
M
-1

You should use the native App Engine mailer: http://code.google.com/appengine/docs/python/mail/sendingmail.html

Metachromatism answered 16/4, 2010 at 22:20 Comment(2)
No. web2py has a layer on top of it. web2py layers should be written to be portable.Stave
"Should" being the operative word... the authors themselves don't even seem too confident that it actually works.Renaldo

© 2022 - 2024 — McMap. All rights reserved.