Ferrous Cranus <ni...@superhost.gr> writes: > Hello, > i have written the following snipper of code to help me send mail: >
[snip] > # prepare mail data > TO = "ni...@superhost.gr" > > SUBJECT = u"Mail από τον επισκέπτη: ( %s )" % FROM > > MESSAGE = "From: %s\r\n" + "To: %s\r\n" + "Subject: %s\r\n" > + MESSAGE + "\r\n" > MESSAGE = MESSAGE % ( FROM, TO, SUBJECT ) > MESSAGE = MESSAGE.encode('utf-8') First a couple of remarks: 1. You should add an empty line between the headers and the message (I suppose the message does not start with an empty line). 2. It is better to do the % substitution only on the headers, not including the message, just in case the message contains a % sign. That makes it: MESSAGE = "From: %s\r\n" + "To: %s\r\n" + "Subject: %s\r\n\r\n" % ( FROM, TO, SUBJECT ) + MESSAGE + "\r\n" MESSAGE = MESSAGE.encode('utf-8') 3. It is bad coding style in Python to use all-caps variables. Better use message instead of MESSAGE etc. [snip] > It works as expected, but the the problem is that it display the FROM > part as being send from ,my personal GMail account when it supposed to > be shown the format variable field that was passed by index.html to the > mail.py script. Where does it display that? Do you happen to read that mail in a Microsoft program? If yes, then it is the fault of that program. Read the mail in some other program and you will probably see that the proper From address is there. The problem is that Gmail inserts a "Sender" header with your account (email address) and certain Microsoft programs use that to display as the From address instead of the real From address. It's against the rules, but then, Microsoft makes its own rules and who is going to stop them? And maybe there are other mail programs that do the same. AFAIK there is no way to get rid of that Sender line. -- Piet van Oostrum <p...@vanoostrum.org> WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] -- https://mail.python.org/mailman/listinfo/python-list