[Tutor] smtplib howto send with a subject line

Daniel McQuay simplebob at gmail.com
Wed May 23 23:52:28 CEST 2007


Thanks Mike, it seems that I'll be easy to incorporate that into my script
as well.

I'll give it a try. I'm still open to other suggestions, though.

On 5/23/07, Mike Hansen <Mike.Hansen at atmel.com> wrote:
>
>
>
> > -----Original Message-----
> > From: tutor-bounces at python.org
> > [mailto:tutor-bounces at python.org] On Behalf Of Daniel McQuay
> > Sent: Wednesday, May 23, 2007 1:49 PM
> > To: tutor at python.org
> > Subject: [Tutor] smtplib howto send with a subject line
> >
> > 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
> >
>
> It seems a little easier to use the email module along with the smtp
> module to create and send a message.
>
> http://docs.python.org/lib/node162.html
>
> Mike
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Daniel McQuay
Linux Jedi
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/3974d657/attachment.html 


More information about the Tutor mailing list