Cannot form correctly the FORM part of the header when sending mail

Ferrous Cranus nikos at superhost.gr
Tue Sep 3 03:48:13 EDT 2013


Hello,
i have written the following snipper of code to help me send mail:


=================================================================================================================
# if html form is submitted then send user mail
#================================================================================================================
if( mailform ):

     try:
         if (FROM is None) or (MESSAGE is None) or ('@' not in FROM) or 
('Γράψε μου εδώ' in MESSAGE):
             print( "<h2><font color=red>Συμπλήρωσε σωστά το mail σου 
και δώσε το σχολιασμό σου!</font></h2>" )
         else:
             # prepare mail data
             TO = "nikos at 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')

             # open Gmail's SMTP server
             server = smtplib.SMTP('smtp.gmail.com:587')
             server.ehlo()
             server.starttls()

             # next, log in to the server
             server.login("nikos.gr33k at gmail.com", "rmrcdherpbsfggcw")

             # send the mail
             server.sendmail( FROM, [TO], MESSAGE )

             print( "<h2><font color=blue>Ευχαριστώ πολύ για το 
ενδιαφέρον! Θα επικοινωνήσω μαζί σου άμεσα :-)</font></h2>" )
     except Exception as e:
         print( repr(e), file=open( '/tmp/err.out', 'a' ) )

     sys.exit(0)
=======================================================================


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.

Si there a workaround for that please?
-- 
Webhost <http://superhost.gr>



More information about the Python-list mailing list