i am trying send email using web2py with gmail and using smtp setting i have attached all code

740 views
Skip to first unread message

deepak sandhu

unread,
Sep 30, 2013, 12:29:58 AM9/30/13
to web...@googlegroups.com
i am trying to create a form in web2py which sends message to an email account on submission mainly i used SQLFORM.factory to create the form then i used gluon.tools import mail to import the send email functionality. i have set up everything i can think of but still on running this code in web2py it gives out that "fail to send email sorry".
i think the problem is in smtp setting or something. 

from gluon.tools import Mail
mail = Mail()

mail.settings.server = 'sm...@gmail.com:465'
mail.settings.sender = 'mye...@gmail.com'
mail.settings.login = 'mye...@gmail.com:secret'




def index(): 

    form = SQLFORM.factory(
    Field('name', requires=IS_NOT_EMPTY()),
    Field('email', requires =[ IS_EMAIL(error_message='invalid email!'), IS_NOT_EMPTY() ]),
    Field('subject', requires=IS_NOT_EMPTY()),
    Field('message', requires=IS_NOT_EMPTY(), type='text')
    )
    if form.process().accepted:
        session.name = form.vars.name
        session.email = form.vars.email
        session.subject = form.vars.subject
        session.message = form.vars.message

        x = mail.send(to=['other...@yahoo.com'],
            subject='project minerva',
            message= "Hello this is an email send from minerva.com from contact us form.\nName:"+ session.name+" \nEmail : " + session.email +"\nSubject : "+session.subject +"\nMessage : "+session.message+ ".\n "
        )

        if x == True:
            response.flash = 'email sent sucessfully.'
        else:
            response.flash = 'fail to send email sorry!'

        #response.flash = 'form accepted.'
    elif form.errors:
        response.flash='form has errors.'

    return dict(form=form)

Massimo Di Pierro

unread,
Oct 1, 2013, 1:36:49 AM10/1/13
to web...@googlegroups.com
This does not look right

mail.settings.server = 'sm...@gmail.com:465'
perhaps should be
mail.settings.server = 'smtp.gmail.com:465'

Jessica Le

unread,
Apr 23, 2014, 3:59:47 PM4/23/14
to web...@googlegroups.com

I've been getting the following error: 

**WARNING:web2py:Mail.send failure:[Errno 11004] getaddrinfo failed**

for the following code: 

        mail = Mail()
    mail.settings.server = 'smtp.gmail.com:587'
    mail.settings.sender = 'em...@gmail.com'
    mail.settings.login = 'em...@gmail.com:password'

    mail.send(to=[email],subject= 'TEST',message='helloWorld')

Can someone please assist me? I can't seem to find any documentation on what getaddrinfo is and where in the code the error is happening. 

Thanks! 



Message has been deleted

NeoToren

unread,
Apr 25, 2014, 5:56:26 PM4/25/14
to web...@googlegroups.com

Michael Beller

unread,
Apr 26, 2014, 6:45:30 AM4/26/14
to web...@googlegroups.com
If you have two step authentication enabled in your gmail account you need to use an application specific password ...

https://support.google.com/mail/answer/1173270?hl=en

NeoToren

unread,
Feb 16, 2015, 12:02:21 PM2/16/15
to web...@googlegroups.com
That's true !
All the issues I have experienced with sending email ("unable to send email") from Web2Py via Gmail, have been caused by the 2-steps authentication which was enabled on my gmail account.

In order for Web2Py to be able to send email via gmail:

2. When logged in with your gmail account, go to https://security.google.com/settings/security/apppasswords?pli=1 and enter the once-only pwd Google provides with the app you intend to allow use the gmail services (I have mentioned "Web2Py")
3. In the model where the mail services are defined - use exactly what's recommended in the W2P book with the new pwd mentioned above - and it works !

Thanks for mentioning it Michael
NeoToren
Reply all
Reply to author
Forward
0 new messages