smtplib needs me to put from/to headers in the message?

Ben Finney bignose+hates-spam at benfinney.id.au
Wed Aug 23 19:36:51 EDT 2006


tobiah <st at tobiah.org> writes:

> In the example at:
> 	http://docs.python.org/lib/SMTP-example.html
> 
> The text of the email message ends up with the From: and To: headers
> in it, and yet the call to sendmail() on the server object requires
> me to specify them again.

[Pet hate issue: Every RFC 2822 email message has exactly *one* body
and *one* header. The header contains multiple fields. Most library
terminology, including the 'smtplib' and 'email' modules, gets this
wrong.]

The smtplib does no processing or parsing of the message data,
correct. You should have the from and to addresses parameterised, use
the 'email' module to create the message and 'smtplib' to send it:

    <URL:http://docs.python.org/lib/module-email.html>
    <URL:http://docs.python.org/lib/node597.html>

-- 
 \      "Puritanism: The haunting fear that someone, somewhere, may be |
  `\                                      happy."  -- Henry L. Mencken |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list