[Zope] Getting email fields right

Bruce Eckel Bruce@EckelObjects.com
Tue, 27 Nov 2001 20:31:39 -0800


I've pretty much come to the conclusion that you don't want to use
the MailHost from within an external method if you want to get the
fields right. You should use a standard python library instead,
such as smtplib. For example, this (adapted from Frederik Lundh's
"Python Standard Library", a book which I consider essential)
works:

import smtplib

def test2(self):
  server = smtplib.SMTP('localhost')
  server.sendmail('Bruce@EckelObjects.com',
    ['Bruce@EckelObjects.com'],
'''From: "Bruce Eckel" <Bruce@EckelObjects.com>
To: "Bruce Eckel" <Bruce@EckelObjects.com>
Subject: for your information


Next week: how to fling an otter
''')
  server.quit()
  return 'sent mail'

It produces the right fields in the sent message.

*********** REPLY SEPARATOR  ***********

On 11/27/01 at 2:07 PM Bruce Eckel wrote:

>I'm using the MailHost to send email from within an external
>method. I've tried a number of different combinations, including
>something as elaborate as this:
>
>self.MailHost.send("This is a test", # Body
>    "To: Bruce Eckel <Bruce@EckelObjects.com>", 
>    "From: Bruce Eckel <Bruce@EckelObjects.com>",  
>     "Test Email") # Subject
>
>However, I can't seem to get the "to" and "from" fields to show up
>right in the resulting email. All I end up with is a 'to' field of
>Bruce@EckelObjects.com
>and an empty 'from' field.
>
>I suspect others have done this before and solved the problem. Or
>will want to :-)
>
>Most current information can be found at:
>http://www.mindview.net/Etc/notes.html
>===================
>Bruce Eckel    http://www.BruceEckel.com
>Contains free electronic books: "Thinking in Java 2e" & "Thinking
>in C++ 2e"
>Please subscribe to my free newsletter -- just send any email to:
>join-eckel-oo-programming@earth.lyris.net
>My schedule can be found at:
>http://www.mindview.net/Calendar
>===================
>
>
>
>_______________________________________________
>Zope maillist  -  Zope@zope.org
>http://lists.zope.org/mailman/listinfo/zope
>**   No cross posts or HTML encoding!  **
>(Related lists - 
> http://lists.zope.org/mailman/listinfo/zope-announce
> http://lists.zope.org/mailman/listinfo/zope-dev )



Most current information can be found at:
http://www.mindview.net/Etc/notes.html
===================
Bruce Eckel    http://www.BruceEckel.com
Contains free electronic books: "Thinking in Java 2e" & "Thinking
in C++ 2e"
Please subscribe to my free newsletter -- just send any email to:
join-eckel-oo-programming@earth.lyris.net
My schedule can be found at:
http://www.mindview.net/Calendar
===================