Saturday, August 4, 2018

python email script

import smtplib

sender = 'from@fromdomain.com'
receivers = ['to@domain.com']

message = """From: From Person
To: To Person
Subject: SMTP e-mail test

This is a test e-mail message.
"""

try:
   smtpObj = smtplib.SMTP('mail.splunk.com')
   smtpObj.sendmail(sender, receivers, message)
   print "Successfully sent email"
except SMTPException:
   print "Error: unable to send email"

No comments: