How to send email in Python via SMTPLIB
Published: September 23, 2009 , Updated: September 23, 2009 , Author: mkyong
Here is an email example written in Python module “smtplib”. It will connect to the GMail SMTP server and do the authentication with username and password given (hardcoded in program), and use the GMail SMTP server to send email to the recipient.
import smtplib to = 'mkyong2002@yahoo.com' gmail_user = 'mkyong2002@gmail.com' gmail_pwd = 'yourpassword' smtpserver = smtplib.SMTP("smtp.gmail.com",587) smtpserver.ehlo() smtpserver.starttls() smtpserver.ehlo smtpserver.login(gmail_user, gmail_pwd) header = 'To:' + to + '\n' + 'From: ' + gmail_user + '\n' + 'Subject:testing \n' print header msg = header + '\n this is test msg from mkyong.com \n\n' smtpserver.sendmail(gmail_user, to, msg) print 'done!' smtpserver.close()
Reference
http://docs.python.org/library/smtplib.html
Any Java questions or problems? please post at this JavaNullPointer.com forum, see you there ~
thank you, it’s work ^_^
great, this is the only correct one I have found. thanks!
It’s works. thank’s mkyong
thanks this is the only link Iv found so far that has worked
Brilliant! Thanks for sharing
Try: this for a similar program snippet wraapped as a function.
wow, that link is great ! thanks for sharing