help with sending mail in Program

Kent Johnson kent37 at tds.net
Tue Jun 7 05:53:25 EDT 2005


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:

#!/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.quit()
    

if __name__ == '__main__':
    
    sendToMe('Testing', 'This is a test')
    



More information about the Python-list mailing list