smtp question

Mike Meyer mwm at mired.org
Wed Jan 5 14:59:35 EST 2005


"Philippe C. Martin" <philippecmartin at sbcglobal.net> writes:

> Hi,
>
> I am testing the smtp module and have the following question:
>
> in the code below (taken from net sample) prior to adding the "Subject:"
> field, the email client found the "From" and the "To". Without the
> "Subject:" field on I get this:
>
> Email client = Evolution: the "From" field is blank
> Email client = KMail: the "To" field is blank
>
> Any clue ?
>
> Thanks and regards,
>
> Philippe
> **********************
>
> import smtplib
>
> def prompt(prompt):
> return raw_input(prompt).strip()
>
>
> fromaddr = prompt("From: ")
> toaddrs  = prompt("To: ").split()
> print "Enter message, end with ^D (Unix) or ^Z (Windows):"
>
> # Add the From: and To: headers at the start!
> msg = ("From: %s\r\nTo: %s\r\n\r\n" % (fromaddr, ", ".join(toaddrs)))
> while 1:
> try:
> line = raw_input()
> except EOFError:
> break
> if not line:
> break
> msg = msg + line
>   
> print "Message length is " + repr(len(msg))
>   
> server = smtplib.SMTP('smtp.sbcglobal.yahoo.com')
> server.set_debuglevel(1)
> server.login ('xxxxx','yyyyyyy')
> server.sendmail(fromaddr, toaddrs, 'Subject:from python\n\n'+msg)

You've got \n\n after the Subject line, not \r\n. That is being treated
as two newlines, thus ending the headers.

   <mike

-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list