Last active
August 29, 2015 14:23
-
-
Save AaronTraas/6fdab15d66cb7b09d4c3 to your computer and use it in GitHub Desktop.
[Python] test email credentials
This file contains 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
#!/usr/bin/python | |
from smtplib import SMTP | |
from email.MIMEText import MIMEText | |
SERVER = "<SMTP_server>" | |
USERNAME = "<SMTP_user_name>" | |
PASSWORD = "<SMTP_password>" | |
DESTINATION = "<destination_email_address>" | |
try: | |
msg = MIMEText('Test message', 'plain') | |
msg['Subject']= "Testing credentials" | |
msg['From'] = USERNAME | |
conn = SMTP(SERVER) | |
conn.set_debuglevel(1) | |
conn.starttls() | |
conn.login(USERNAME, PASSWORD) | |
try: | |
conn.sendmail(USERNAME, DESTINATION, msg.as_string()) | |
finally: | |
conn.close() | |
except Exception, exc: | |
sys.exit( "Sending mail failed: %s" % str(exc) ) # give a error message |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I find this useful to verify SMTP credentials sent to me by a client.
Modified from code found here: http://stackoverflow.com/questions/64505/sending-mail-from-python-using-smtp