2 years ago
#21030
jmhobaica
Python smtplib smtp.gmail.com script working in my localhost but not in my server
I'm facing an issue while running a python script to send emails through smtp.gmail.com. When I execute it in my localhost, it works as a charm, but once I export it to my server and I execute it there, I get the (535, b'Incorrect authentication data') error.
I already went further and compared responses in both places through server.set_debuglevel(1) and this is the result:
In my PC where it works perfect:
send: 'ehlo [192.168.0.100]\r\n'
reply: b'250-smtp.gmail.com at your service, [201.234.227.142]\r\n'
reply: b'250-SIZE 35882577\r\n'
reply: b'250-8BITMIME\r\n'
reply: b'250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH\r\n'
reply: b'250 2.0.0 OK blablabla\r\n'
reply: retcode (250); Msg: b'2.0.0 OK blablabla'
data: (250, b'2.0.0 OK blablabla')
send: 'quit\r\n'
reply: b'221 2.0.0 blablabla\r\n'
In my server:
send: 'ehlo [theAddressOfMyServer]\r\n'
reply: b'250-**[theAddressOfMyServer AGAIN?????]** Hello [theAddressOfMyServer]m [the IP]\r\n'
reply: b'250-SIZE 52428800\r\n'
reply: b'250-8BITMIME\r\n'
reply: b'250-PIPELINING\r\n'
reply: b'250-PIPE_CONNECT\r\n'
reply: b'250-AUTH PLAIN LOGIN\r\n'
reply: b'250 HELP\r\n'
reply: retcode (250); Msg: b'[theAddressOfMyServer] Hello [theAddressOfMyServer] [the IP]\nSIZE 52428800\n8BITMIME\nPIPELINING\nPIPE_CONNECT\nAUTH PLAIN LOGIN\nHELP'
send: 'AUTH PLAIN blablabla=\r\n'
reply: b'535 Incorrect authentication data\r\n'
reply: retcode (535); Msg: b'Incorrect authentication data'
send: 'AUTH LOGIN blablabla==\r\n'
reply: b'334 UGFzc3dvcmQ6\r\n'
reply: retcode (334); Msg: blablabla'
send: 'blablabla=\r\n'
reply: b'535 Incorrect authentication data\r\n'
reply: retcode (535); Msg: b'Incorrect authentication data'
Notice how in my PC, gmail replies with "smtp.gmail.com at your service", but in my server, it never makes contact with gmail (thus, the authentication error), but seems to be talking with itself (??????). Could my server be blocking smtp.gmail.com? Or could my server be somehow blacklisted? This happens with any Google account, and I have also enabled "Less secure apps".
Here is my code:
import smtplib, ssl
port = 465
user = 'myCompletelyValidUser@gmail.com'
password = 'MyPerfectPassword'
# Do you think I should add a context? default one throws another exception
# of invalid authentication, as the server is talking 'with itself'
context = None
message = """\
Subject: Hi there
This message is sent from Python."""
server = smtplib.SMTP_SSL('smtp.gmail.com', port=port, context=context)
server.set_debuglevel(1)
server.login(user, password)
server.sendmail(user, [theRecipientAddress], message)
server.quit()
Any help will be appreciated! Thanks guys! JMH
python
gmail
smtplib
0 Answers
Your Answer