email sending problem

92 views
Skip to first unread message

e27...@gmail.com

unread,
Jun 4, 2017, 12:04:47 PM6/4/17
to web2py-users
Hello everyone.

I am quite desperate. I can not send email using smtp.gmail.com. Nothing seams to be working. I use a gmail smtp account which is working fine on my server when I use a basic python script, or even a php script on my Apache 2.4. But is not not working with Web2py. I do not have the 2 identification activated on gmail.

What i did :

I created a news application. In the db.py file, I have put the following lines :

from gluon.tools import Auth, Service, PluginManager

auth = Auth(db)
service = Service()
plugins = PluginManager()

## create all tables needed by auth if not custom tables
auth.define_tables(username=False, signature=False)

## configure email
mail = auth.settings.mailer
mail.settings.server = 'smtp.gmail.com:587'
mail.settings.sender = 'eXX...@gmail.com'
mail.settings.login = 'eXX...@gmail.com:XXXXX'


In the default.py file, I just put the following line :

def index():

    mail.send('eXX...@gmail.com','Subject','Message')
  
    response.flash = T("Hello World")
    return dict(message=T('Welcome to web2py!'))


I have not error messages, but no mail was sent.

Any idea ?

Thank you very much.

------------------

Version

2.14.6-stable+timestamp.2016.05.10.00.21.47
(Running on Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/7.0.10 mod_wsgi/4.4.12 Python/2.7.10, Python 2.7.10)



Massimo Di Pierro

unread,
Jun 4, 2017, 12:17:21 PM6/4/17
to web2py-users
I will try provide a more details answer but for now this is what I know:

1) mail.send(...) returns True or False so you can check if the email was sent
2) mail.send uses SMTP with logs errors using a logger. This means there is no ticket but you use a logger as explained here, you should be able to capture them. https://stackoverflow.com/questions/19787198/logging-in-web2py

I have not tried 2 myself.

Ron Chatterjee

unread,
Jun 4, 2017, 12:30:32 PM6/4/17
to web2py-users
First make sure gmail is set up as less secured app.

e27...@gmail.com

unread,
Jun 4, 2017, 12:44:07 PM6/4/17
to web2py-users

Gmail is working fine for sending email, along with the other IP (orange, free) that I used.

e27...@gmail.com

unread,
Jun 4, 2017, 12:54:03 PM6/4/17
to web2py-users

Since mail.send() return False or True, there is no error here. I am not sur we can log any error here.

How could I get the same "Warning" information that I can have through the local Web2py console which displays the real reason why an email is not sent ?

Dave S

unread,
Jun 5, 2017, 1:47:07 PM6/5/17
to web2py-users


On Sunday, June 4, 2017 at 9:54:03 AM UTC-7, e27...@gmail.com wrote:

Since mail.send() return False or True, there is no error here. I am not sur we can log any error here.

How could I get the same "Warning" information that I can have through the local Web2py console which displays the real reason why an email is not sent ?

Massimo is saying that mail.send will put the error information in your log file if you enable logging in your application.   In addition to the stackoverflow reference he provided, there's a short section in the book

<URL:http://web2py.com/books/default/chapter/29/04/the-core#Logging>

It's easy enough to do ... I've managed it, despite being attached to "print" statements.
And you should be able to get the failure information you need from the logs,
without having to set up a remote console.

/dps


Reply all
Reply to author
Forward
0 new messages