Getting email fields right
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 ===================
I am having that problem and am eager to here a solution.. Robert
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 ===================
Some header problems are fixed in 2.4.3. Other problems are fixed in a HotFix I made: http://www.zope.org/Members/regebro/mailhostfix There may be more... :-) Using smtplib is easy enough though... ----- Original Message ----- From: "Bruce Eckel" <Bruce@EckelObjects.com> To: <zope@zope.org> Sent: Wednesday, November 28, 2001 5:31 AM Subject: Re: [Zope] Getting email fields right
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.
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 :-)
Hi Bruce With the help of Lundh's *Python Standard Library* I got to the following. This is in the external method: import string def testmail(self): message = "This is a test" mto = "Bruce@EckelObjects.com" mfrom = "Bruce@EckelObjects.com" subject = "Test Email" encode = None body = string.join(( "From: %s" % mfrom, "To: %s" % mto, "Subject: %s" % subject, "", message), "\r\n") self.MailHost.send(body, [mto], mfrom, subject, encode) Greetings --- Flynt
Thanks ... except, it doesn't actually work. I installed it and tried it, and it sends email but the From and To fields are not filled out properly. Using smtplib does work, however. *********** REPLY SEPARATOR *********** On 11/28/01 at 1:13 PM flynt wrote:
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 :-)
Hi Bruce
With the help of Lundh's *Python Standard Library* I got to the following. This is in the external method:
import string def testmail(self): message = "This is a test" mto = "Bruce@EckelObjects.com" mfrom = "Bruce@EckelObjects.com" subject = "Test Email" encode = None
body = string.join(( "From: %s" % mfrom, "To: %s" % mto, "Subject: %s" % subject, "", message), "\r\n")
self.MailHost.send(body, [mto], mfrom, subject, encode)
Greetings
--- Flynt
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 ===================
Hi Bruce I am puzzled a bit. I tested before I sent you the message. And I tested more after your reply that it did not work for you. Furthermore, looking in the source code, the Mailhost product's *MailHost.send* method does nothing else than using smtplib. So if Fredric Lundh's receipt is working with smtplib, it should do so with Zope's Mailhost. I tested with: - Zope 2.3.3 and Zope 2.4.3 on Linux - Zope 2.4.3 on Windows XP - Email clients Netscape Messenger and MS Outlook - different SMTP servers in the MailHost object: Intranet (Sendmail and MS Exchange), mx0.gmx.net (qmail) - different sender and recipients addresses (Intranet and GMX) - by using test tab of the external method and by calling the external method from a DTML method. For all cases it works. I could reproduce your original problem (I got the from part in the email, but for recipients I got only *Undisclosed recipients*), but I cannot reproduce the problems with the wrong (missing ?) *from* and *to* you are reporting now. I *do* get the *from* and *to* fields correctly filled when using the external method that I copy-pasted into the email that I have sent earlier. Sorry, at the moment I have no idea about what might be the problem. Maybe someone else has an idea ? And I do not understand why it should work with smtplib but not with Zope's Mailhost object's *send* method. --- Flynt Bruce Eckel wrote:
Thanks ... except, it doesn't actually work. I installed it and tried it, and it sends email but the From and To fields are not filled out properly.
Using smtplib does work, however.
*********** REPLY SEPARATOR ***********
On 11/28/01 at 1:13 PM flynt wrote:
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 :-)
Hi Bruce
With the help of Lundh's *Python Standard Library* I got to the following. This is in the external method:
import string def testmail(self): message = "This is a test" mto = "Bruce@EckelObjects.com" mfrom = "Bruce@EckelObjects.com" subject = "Test Email" encode = None
body = string.join(( "From: %s" % mfrom, "To: %s" % mto, "Subject: %s" % subject, "", message), "\r\n")
self.MailHost.send(body, [mto], mfrom, subject, encode)
Greetings
--- Flynt
It turns out this was a bug with MailHost, that was fixed in 2.4.3. I'm running 2.4.2. *********** REPLY SEPARATOR *********** On 11/29/01 at 3:56 PM flynt wrote:
Hi Bruce
I am puzzled a bit. I tested before I sent you the message. And I tested more after your reply that it did not work for you. Furthermore, looking in the source code, the Mailhost product's *MailHost.send* method does nothing else than using smtplib. So if Fredric Lundh's receipt is working with smtplib, it should do so with Zope's Mailhost.
I tested with: - Zope 2.3.3 and Zope 2.4.3 on Linux - Zope 2.4.3 on Windows XP - Email clients Netscape Messenger and MS Outlook - different SMTP servers in the MailHost object: Intranet (Sendmail and MS Exchange), mx0.gmx.net (qmail) - different sender and recipients addresses (Intranet and GMX) - by using test tab of the external method and by calling the external method from a DTML method. For all cases it works.
I could reproduce your original problem (I got the from part in the email, but for recipients I got only *Undisclosed recipients*), but I cannot reproduce the problems with the wrong (missing ?) *from* and *to* you are reporting now. I *do* get the *from* and *to* fields correctly filled when using the external method that I copy-pasted into the email that I have sent earlier.
Sorry, at the moment I have no idea about what might be the problem. Maybe someone else has an idea ? And I do not understand why it should work with smtplib but not with Zope's Mailhost object's *send* method.
--- Flynt
Bruce Eckel wrote:
Thanks ... except, it doesn't actually work. I installed it and tried it, and it sends email but the From and To fields are not filled out properly.
Using smtplib does work, however.
*********** REPLY SEPARATOR ***********
On 11/28/01 at 1:13 PM flynt wrote:
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 :-)
Hi Bruce
With the help of Lundh's *Python Standard Library* I got to the following. This is in the external method:
import string def testmail(self): message = "This is a test" mto = "Bruce@EckelObjects.com" mfrom = "Bruce@EckelObjects.com" subject = "Test Email" encode = None
body = string.join(( "From: %s" % mfrom, "To: %s" % mto, "Subject: %s" % subject, "", message), "\r\n")
self.MailHost.send(body, [mto], mfrom, subject, encode)
Greetings
--- Flynt
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 ===================
participants (4)
-
Bruce Eckel -
flynt -
Lennart Regebro -
Robert Rottermann