Cannot form correctly the FORM part of the header when sending mail
Piet van Oostrum
piet at vanoostrum.org
Fri Sep 6 00:48:32 EDT 2013
Nikos, if you can't use the smtp server at mail.superhost.gr, or if that
has the same restrictions I may have a solution for you. This is a bit
off-topic on the Python list/group, s I will throw in a line of Python
code to make it on-topic :)
I suppose you have the following reasons to want to have the original
email address in the message: (1) so that you can see who sent the
message, (2) so that you can reply to the original sender.
Let's say that the from address was user at example.com
Problem 1 can be solved in two ways:
(a) Just put the email address in front of the subject line, like:
Subject: (From user at example.com) Original subject line
(b) This solution is a bit more tricky.
- Get a separate email address that you use for these messages, like
nikos at hotmail.com. Register this as one of your email addresses in
gmail. For this it must be a real email address that belongs to you,
not a fake address. When it is registered with gmail, gmail will not
change it if found in a From header. Make sure that Thunderbird DOES
NOT KNOW that this email address belongs to you (i.e. don't use this
email address for normal work). Gmail will send you a message to this
address to verify that it belongs to you so you must access it through
some other means, like a web interface.
- Now in the generated email you put the original sender in the comment
and your new email address as the real address like:
From: "user at example.com" <nikos at hotmail.com>
Because Thunderbird doesn't know nikos at hotmail.com it will display the
other one, user at example.com. Make sure that the email address doesn't
contain a quote character. Better still check that only legal characters
are used.
Problem 2 can easily be solved by adding a Reply-To header with the
original from address. Gmail will not change this.
So the code becomes something like:
MESSAGE = "From: \"{0}\" <nikos at hotmail.com>\r\n" "Reply-To: {0}\r\n" "To: {1}\r\n" "Subject: (From {0}) {2}\r\n\r\n{3}\r\n".format(FROM, TO, SUBJECT, MESSAGE)
In my opinion a better solution would be to filter your mesaage through
procmail or similar on your receiving computer. For example put the from
address in an X-From header and let the filter replace the From header
with the address from the X-From.
--
Piet van Oostrum <piet at vanoostrum.org>
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
More information about the Python-list
mailing list