I need to send mails from my Python3 script. Now it does, but my gmail password is visible and I cannot trust in any admin of this machine, so the solution I see is to mount a local mail server. To do some tests, I was trying to execute a script (this one: SMTP sink server). While this one is running, I execute my old script with some changes:
import smtplib
# server = smtplib.SMTP('smtp.gmail.com:587')
server = smtplib.SMTP('localhost:25')
# smtp.ehlo()
# server.starttls()
# smtp.ehlo()
# server.login('my_account@gmail.com', 'my_password')
server.login(None, None)
server.sendmail('Me <my_account@gmail.com'>, ['to_user@gmail.com'], 'Hi!'.as_string())
server.quit()
I understand the script at the link will create a file in the folder where it is with the mail content, but nothing happens, because I get this error message:
SMTP AUTH extension not supported by server.
I googled and I think this could be sorted out if I uncomment the line server.starttls()
, but it gives another error, which is supposed to be solved with the lines smtp.ehlo()
, but not in my case.
Any suggestions?
OK, I managed to send the email, what I only had to do was removing this line:
server.login(None, None)