[Tutor] Mail? What's that?

Ricardo Aráoz ricaraoz at gmail.com
Thu Dec 6 03:09:05 CET 2007

So I eventually got to sending mail with python.
Some articles, trying and google led me to this script:

import smtplib
import time

date = time.ctime(time.time( ))
>From = 'mymail at gmail.com'
To = ['othermail at hotmail.com', 'YetOtherMail at yahoo.com']
Subj = 'Hi'
text = ('From: %s\nTo: %s\nDate: %s\nSubject: %s\n\n'
                         % (From, ';'.join(To), date, Subj))

s = smtplib.SMTP('smtp.gmail.com')
s.login('foo', 'bar')
s.sendmail(From, To, text)

So, if there's someone who really knows this stuff in the neighborhood
I'd like to ask a couple of questions.
What is ehlo and why do I have to call it twice? And set_debuglevel?
If I where to connect through other smtp server the sequence would be
the exactly the same, say yahoo or hotmail?
Are From: To: Date: and Subject: mandatory in the contents of the
email(text)?  Do I have to put "real" address in  From when calling
sendmail()? And in the contents?
Ok, if someone can answer these I'll be grateful.



More information about the Tutor mailing list