Reputation: 43
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('[email protected]','password')
server.sendmail('[email protected]','[email protected]','msg')
server.close()
print("SUCCESS")
import smtplib
server = smtplib.SMTP('smpt.gmail.com', 587)
server.ehlo()
server.starttls()
server.login('[email protected]','password')
server.sendmail('[email protected]','[email protected]','msg')
server.close()
print("SUCCESS")
there is no literal difference but the first one works and the second one doesnt
Upvotes: 2
Views: 131
Reputation: 16147
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.
Upvotes: 3
Reputation: 503
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/
Upvotes: 1