help with sending mail in Program

Tim Roberts timr at probo.com
Thu Jun 9 00:41:20 EDT 2005


Kent Johnson <kent37 at tds.net> wrote:

>Ivan Shevanski wrote:
>> Could someone send me a good tutorial for sending mail then? The one I 
>> found is not what I'm looking for.  Also please dont send me the stmp 
>> definition cause i've looked at that enough.
>
>Here is a module I use to send mail to myself using smtplib:

Not exactly like this, you didn't.  The list of destination addresses in
SMTP.sendmail must be a sequence, not a string:

>#!/usr/local/bin/python
>
>''' Send mail to me '''
>
>from smtplib import SMTP
>
>def sendToMe(subject, body):
>    me = '"Kent Johnson" <me at mycompany.com>'
>    send(me, me, subject, body)
>    
>    
>def send(frm, to, subject, body):
>    s = SMTP()
>#    s.set_debuglevel(1)
>    s.connect('mail.mycompany.com')
>    s.ehlo('10.0.3.160') # IP address of my computer, I don't remember why I needed this
>    
>    msg = '''From: %s
>Subject: %s
>To: %s
>
>%s
>''' % (frm, subject, to, body)
>
>    s.sendmail(frm, to, msg)

    s.sendmail(frm, [to], msg)

>    s.quit()
>    
>
>if __name__ == '__main__':
>    sendToMe('Testing', 'This is a test')
-- 
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-list mailing list