开发者

Sending email from an web2py on GAE

开发者 https://www.devze.com 2022-12-27 09:35 出处:网络
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 give开发者_运维问答n with the web2py. Does anybody how to do this?

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 give开发者_运维问答n 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


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="you@example.com"
mail.settings.tls=True or False
mail.settings.login="you:password"

It supports multiple encodings, MIME and attachments.


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="you@example.com" #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 (celso.gcosta@gmail.com) Brazil World Cup champion soccer 2010


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

0

精彩评论

暂无评论...
验证码 换一张
取 消