Problem sending emails. Various errors from different Ports

215 views
Skip to first unread message

4ringmaster

unread,
Jul 27, 2016, 2:56:22 AM7/27/16
to web2py-users
This is my code: 

from gluon.tools import Mail
mail = Mail()
mail.settings.server = 'smtp.gmail.com:465'
mail.settings.sender = 'sendin...@gmail.com'
mail.settings.login = 'sending-email:password'
mail.settings.ssl = True
mail.settings.tls = True

@auth.requires_signature()
def send_contact_form():
x = mail.send(to=['receivi...@gmail.com'],
subject='Test',
message="Test Message")
if x == True:
print "Email sent successfully"
else:
print "Nope"
print x
print mail.result
print mail.error

return 'ok'

The sending email is an email address that I have had for many years. It doesn't have any 2 step-verification on it, access for less secure apps has been turned on, and both POP and IMAP is enabled for it. I've tried connecting to ports 25, 465, 587, and 993 with no success. 
I have tried everything on Google's SMTP setup page, but nothing has worked. 

Errors I get when using 'smtp.gmail.com:25':
Nope
WARNING:web2py:Mail.send failure:[Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
False
{}
[Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

Errors I get when using 'smtp.gmail.com:465':
Nope
False
{}
(534, '5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbuD\n5.7.14 WXRGlkuzK7dK0d0H9cK3MaCX62ZEQzxju19EBPw67c-uTyKzhSEhIjM50JOVS3OKGtJV63\n5.7.14 d2F2kbtxaNWRP_plb2zF2VHwDNjrot97Jckf0f5VZy7iorl9s08WANnni-J_TR1F2L3xcM\n5.7.14 fX9PHbhrDZJRULhHZAnaXSd_kOHhCqXyY5OS-V4oKbMneApZ4fYcib85z-8OBWEuTbeVsa\n5.7.14 M1RU0KRCFbu8ro5uTv-kQIGkgMKA8> Please log in via your web browser and\n5.7.14 then try again.\n5.7.14  Learn more at\n5.7.14  https://support.google.com/mail/answer/78754 x5sm4457200pax.33 - gsmtp')
WARNING:web2py:Mail.send failure:(534, '5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbuD\n5.7.14 WXRGlkuzK7dK0d0H9cK3MaCX62ZEQzxju19EBPw67c-uTyKzhSEhIjM50JOVS3OKGtJV63\n5.7.14 d2F2kbtxaNWRP_plb2zF2VHwDNjrot97Jckf0f5VZy7iorl9s08WANnni-J_TR1F2L3xcM\n5.7.14 fX9PHbhrDZJRULhHZAnaXSd_kOHhCqXyY5OS-V4oKbMneApZ4fYcib85z-8OBWEuTbeVsa\n5.7.14 M1RU0KRCFbu8ro5uTv-kQIGkgMKA8> Please log in via your web browser and\n5.7.14 then try again.\n5.7.14  Learn more at\n5.7.14  https://support.google.com/mail/answer/78754 x5sm4457200pax.33 - gsmtp')

Errors I get when using 'smtp.gmail.com:587':
WARNING:web2py:Mail.send failure:[SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:590)
Nope
False
{}
[SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:590)

Errors I get when using 'smtp.gmail.com:993':
WARNING:web2py:Mail.send failure:(-1, 'Gimap ready for requests from 50.150.125.89 py13mb358160253pab')
Nope
False
{}
(-1, 'Gimap ready for requests from 50.150.125.89 py13mb358160253pab')

Sorry for the long errors, but I can't see what I'm doing wrong.

Jose C

unread,
Jul 28, 2016, 6:18:29 AM7/28/16
to web...@googlegroups.com
Hi,

AFAIK you must use port 587 with gmail.  Also, I suspect setting ssl=True is causing issues (port 587 uses TLS).  Try removing:

mail.settings.ssl = True
mail
.settings.tls = True



This is how I do it with gmail:

mail
.settings.sender = 'm...@gmail.com'
mail
.settings.server =  'smtp.gmail.com:587'
mail
.settings.login = 'me:my_passw'

sent_ok
= mail.send(
                    to
= [sendto_add],
                    sender
= sender,
                    bcc
= [bcc],
                    subject
= subject,
                    message
= (body_txt, body_html)
                   
)



HTH,
Jose

4ringmaster

unread,
Jul 28, 2016, 5:28:07 PM7/28/16
to web2py-users
It probably would have worked with the way used in the book, but to get it to work I had to create a new gmail account, and use the smtplib for python. My code ended up looking like: 

import smtplib
def send_contact_form():
message = "Test"
mail = smtplib.SMTP('smtp.gmail.com', 587)
mail.ehlo()
mail.starttls()
mail.login('sendin...@gmail.com', 'password')
mail.sendmail('sendin...@gmail.com', 'receivi...@gmail.com', message)
mail.close()

return 'ok'
Reply all
Reply to author
Forward
0 new messages