[Tutor] smtplib howto send with a subject line
Daniel McQuay
simplebob at gmail.com
Wed May 23 21:49:21 CEST 2007
Hey Guys, I'm having a problem with my script that sends out an email using
smtplib. Whats happening now is when it is send I get a (no subject) where
the subject line should be. I checked a few places such as effbot and some
other online doc but couldn't find any thing about the subject line.
Any help would be much appreciated.
###################################
#Created by: Daniel McQuay
#This script will send and email
#to verify if the backup was
#successful or not.
###################################
import smtplib
import sys
emmssg = "/tmp/backup.log"
smtpserver = 'localhost'
AUTHREQUIRED = 0
smtpuser = ''
smtppass = ''
#Recipients who will be getting the emails
RECIPIENTS = ['simplebob at gmail.com']
SENDER = 'Saint_Richards'
#This does not work?
SUBJECT = 'Backup_Log'
emmssg = open('/tmp/backup.log','r').read()
session = smtplib.SMTP(smtpserver)
if AUTHREQUIRED:
session.login(smtpuser, smtppass)
smtpresult = session.sendmail(SENDER, RECIPIENTS, SUBJECT, emmssg)
if smtpresult:
errstr = ""
for recip in smtpresult.keys():
errstr = """Could not delivery mail to: %s
Server said: %s
%s
%s""" % (recip, smtpresult[recip][0], smtpresult[recip][1], errstr)
raise smtplib.SMTPException, errstr
Thanks in advance,
--
Daniel McQuay
Jaluno.com
H: 814.825.0847
M: 814-341-9013
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070523/312df417/attachment.htm
More information about the Tutor
mailing list