Cannot form correctly the FORM part of the header when sending mail
Piet van Oostrum
piet at vanoostrum.org
Wed Sep 4 17:38:33 EDT 2013
Piet van Oostrum <piet at vanoostrum.org> writes:
> Ferrous Cranus <nikos.gr33k at gmail.com> writes:
>
>> I this hoq you mean?
> [...]
>>
>> SUBJECT = u"Mail από τον επισκέπτη: ( %s )" % FROM
>>
>> MESSAGE = "\nFrom: %s\r\n" + "To: %s\r\n" + "Subject: %s\r\n\r\n" % ( FROM, [TO], SUBJECT ) + MESSAGE + "\r\n"
>> MESSAGE = MESSAGE.encode('utf-8')
> [...]
>> but now iam getting this error message:
>>
>> sendmail => %s 13-09-04 12:29:22 (<class 'TypeError'>, TypeError('not all arguments converted during string formatting',), <traceback object at 0x7f0e432e1cb0>)
>>
> That is because you changed TO in [TO]. That causes the error.
>
> ** And the \n at the beginning shouldn't be there. **
>
> MESSAGE = "From: %s\r\n" + "To: %s\r\n" + "Subject: %s\r\n\r\n" % ( FROM, TO, SUBJECT ) + MESSAGE + "\r\n"
>
> You could even change that to:
>
> MESSAGE = "From: %s\r\n" + "To: %s\r\n" + "Subject: %s\r\n\r\n%s\r\n" % (FROM, TO, SUBJECT, MESSAGE)
There was another error in that line:
The string at the left of the % should be in parentheses, or be a single
string:
MESSAGE = ("From: %s\r\n" + "To: %s\r\n" + "Subject: %s\r\n\r\n%s\r\n") % ( FROM, TO, SUBJECT, MESSAGE)
or
MESSAGE = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n%s\r\n" % ( FROM, TO, SUBJECT, MESSAGE)
or even
MESSAGE = "From: %s\r\n" "To: %s\r\n" "Subject: %s\r\n\r\n%s\r\n" % ( FROM, TO, SUBJECT, MESSAGE)
Another note:
I did some expriments with Gmail and it seems that it also changes the
>From header if the address given is not one that you registerd with your
gmail account. So it is even worse than I thought. (In practice I didn't
notice this because I have all the email addresses I use registered.)
--
Piet van Oostrum <piet at vanoostrum.org>
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
More information about the Python-list
mailing list