In this script I am using gmail, but it is not limited to Google as long as your provide the correct smtp server + port.
Python 2.7.3
- from email.mime.text import MIMEText
- import smtplib
- def sendmail(to,subject,text):
- user = 'name@gmail.com'
- pwd = 'password'
- msg = MIMEText(text)
- msg['From'] = 'james@gmail.com'
- msg['To'] = to
- msg['Subject'] = subject
- try:
- smtpServer = smtplib.SMTP('smtp.gmail.com', 587)
- smtpServer.ehlo()
- smtpServer.starttls()
- smtpServer.ehlo()
- smtpServer.login(user, pwd)
- smtpServer.sendmail(user, to, msg.as_string())
- smtpServer.close()
- print "mail sent."
- except SMTPException:
- print "failed."
No comments:
Post a Comment