Skip to content

Instantly share code, notes, and snippets.

@srijanshetty
Last active August 29, 2015 14:04
Show Gist options
  • Save srijanshetty/ff4e4086c9be6106cb79 to your computer and use it in GitHub Desktop.
Save srijanshetty/ff4e4086c9be6106cb79 to your computer and use it in GitHub Desktop.
SMTP client
#!/bin/python
def send_mail():
import smtplib
gmail_user=''
gmail_password=''
FROM=''
TO=['', '']
SUBJECT='This is a random experiment'
TEXT='Congratulations this works'
message='FROM: %s\nTO: %s\nSUBJECT: %s\n\n %s' %(FROM, ','.join(TO), SUBJECT, TEXT)
try:
server = smtplib.SMTP('smtp.gmail.com', 587)
print 'Establishing Connection'
server.ehlo()
print 'Setting up TLS'
server.starttls()
print 'Restablishing TLS connection'
server.ehlo()
print 'Authenticating user'
server.login(gmail_user, gmail_password)
print 'Sending Message'
server.sendmail(FROM, TO, message)
print 'Closing Connection'
server.close()
except:
print 'Message not sent'
send_mail()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment