using smtp class in python to send automated emails

Viewed 51

So i am experimenting with the SMTP module in python and the code i was using, wasnt working. i found a solution on stack overflow which literally was the same code as mine but worked. Can someone please find a difference or tell me why my code wasnt working my code is the second block

import smtplib
server = smtplib.SMTP('smtp.gmail.com',587)
server.ehlo()
server.starttls()
server.login('example@gmail.com','password')
server.sendmail('example@gmail.com','recipient@gmail.com','msg')
server.close()
print("SUCCESS")




import smtplib
server = smtplib.SMTP('smpt.gmail.com', 587)
server.ehlo()
server.starttls()
server.login('example@gmail.com','password')
server.sendmail('example@gmail.com','recipient@gmail.com','msg')
server.close()
print("SUCCESS")

there is no literal difference but the first one works and the second one doesnt

2 Answers

Maybe you meant to type

smtp.gmail.com instead of stmp.gmail.com

Next time try diffchecker.com or something similar to make sure the two blocks of code are actually the same, because in this case they aren't in a very important way.

I guess you didn't configure your google account to accept your smtp requests.

To be able to send emails via your Gmail account, you need to provide access to it for your application. You can Allow less secure apps or take advantage of the OAuth2 authorization protocol. It’s a way more difficult but recommended due to the security reasons.

https://julien.danjou.info/sending-emails-in-python-tutorial-code-examples/

Related