Last active
August 29, 2015 14:04
-
-
Save srijanshetty/ff4e4086c9be6106cb79 to your computer and use it in GitHub Desktop.
SMTP client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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