RE: email libraries in python?
- From: Rodney Haynie <RodneyH@xxxxxxxxxx>
- To: "programmingblind@xxxxxxxxxxxxx" <programmingblind@xxxxxxxxxxxxx>
- Date: Tue, 30 Dec 2008 14:11:00 -0500
Tyler,
Ok, I had this example on my box. I quickly renamed the hardcoded email
addresses, but you can get the idea. I also had this setup with a timer, so it
would send an email every so often. I was having some fun with my coworkers...
(smile).
Works with Python 2.5.
Good luck.
-Rodney
from threading import *
import smtplib
from email.MIMEText import MIMEText
def tm():
# Set up a MIMEText object (it's a dictionary)
msg = MIMEText("This is very important...")
# You can use add_header or set headers directly ...
msg['Subject'] = 'Note from my computer'
# Following headers are useful to show the email correctly
# in your recipient's email box, and to avoid being marked
# as spam. They are NOT essential to the snemail call later
msg['From'] = "FName LName"
msg['Reply-to'] = "somename@xxxxxxxxxxxxx"
msg['To'] = "somebody@xxxxxxxxxxxxx"
server = smtplib.SMTP('exchsrv07.ad.somewhere.com')
# server.set_debuglevel(1)
From = "somebody@xxxxxxxxxxxxx"
To = "somebody@xxxxxxxxxxxxx"
server.sendmail(From, To, msg.as_string())
To = "somebody@xxxxxxxxxxxxx"
server.sendmail(From, To, msg.as_string())
# To = "joem@xxxxxxxxxxxxx"
# server.sendmail(From, To, msg.as_string())
To = "somebody@xxxxxxxxxxxxx"
server.sendmail(From, To, msg.as_string())
server.quit()
t = Timer(1.0 * 2, tm)
t.start()
Other related posts: