views:

341

answers:

3

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

A: 

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

dkamins
No. web2py has a layer on top of it. web2py layers should be written to be portable.
mdipierro
*"Should"* being the operative word... the authors themselves don't even seem too confident that it actually works.
Jason Hall
...massimo is the author
Plumo
+1  A: 

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.

mdipierro
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 GAE
Felix
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"
mdipierro
A: 

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

Celso