Cannot form correctly the FORM part of the header when sending mail
Piet van Oostrum
piet at vanoostrum.org
Wed Sep 4 12:16:05 EDT 2013
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)
which I think is nicer.
--
Piet van Oostrum <piet at vanoostrum.org>
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
More information about the Python-list
mailing list