#1
  1. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,280
    Rep Power
    13

    Sending mail vwith sendmail via Python code


    Code:
     SENDMAIL = '/usr/sbin/sendmail' 
                             
                    FROM = mail 
                    TO = ['support@superhost.gr'] 
                    SUBJECT = "Επικοινωνία πιθανού πελάτη!" 
                    TEXT = comment 
    
                    message = """\ 
                                      From: %s 
                                      To: %s 
                                      Subject: %s 
                                               
                                      %s 
                                      """ % (FROM, ", ".join(TO), SUBJECT, TEXT) 
    
                    p = os.popen("%s -t -i" % SENDMAIL, "w") 
                    p.write(message) 
                    status = p.close() 
                    if status != 256: 
                            print( "<h2><font color=lime>Ευχαριστώ πολύ για το ενδιαφέρον! Θα επικοινωνήσω μαζί σου άμεσα :-)</font></h2>" ) 
                    else: 
                            print( "<h2><font color=red>Δυστυχώς δεν μπόρεσε να αποσταλεί το e-mail :-(" )
    ===============

    Do you see somehtign wrong in the above code and mail never makes it to the recipient(that my address) ?
    What is now proved was once only imagined!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    138
    Rep Power
    2
    Have you verified that you can send mail using "sendmail" manually?

    If so, I would then troubleshoot this by printing out the exact command you're trying to use, and then check the output data and return code in your python code. Paste that and we can continue troubleshooting.
  4. #3
  5. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,280
    Rep Power
    13
    Please type in precisely what i shopuld try on the remote shell in cmd so i can try it.
    What is now proved was once only imagined!
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    138
    Rep Power
    2
    Originally Posted by Nik
    Please type in precisely what i shopuld try on the remote shell in cmd so i can try it.
    This is somewhat off-topic as this is a python forum, but try the examples here: http://govath.wordpress.com/2011/09/20/sendmail-linux-examples/

    If you have the "mail" command available, it might be easier to use that.

    Code:
    echo “Message body” | mail -s “subject” recipient@domain.com -c cc.recipient@domain.com
  8. #5
  9. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,280
    Rep Power
    13
    Hey man this worked via Python!

    Code:
    # =================================================================================================================
    # if html form is submitted then send user mail
    # =================================================================================================================
    if( userform ):
    
    	if (mail is None) or (comment is None) or ('@' not in mail) or ('Γράψε μου εδώ το σχόλιο σου!' in comment):
    		print( "<h2><font color=red>Συμπλήρωσε σωστά το mail σου και δώσε το σχολιασμό σου!</font></h2>" )
    	else:	
    		FROM = mail
    		MESSAGE = comment
    
    		if( os.system( 'echo "%s" | mail -s "%s" support@superhost.gr' % (MESSAGE, FROM) ) ):
    			print( "<h2><font color=red>Δυστυχώς δεν μπόρεσε να αποσταλεί το e-mail :-(" )
    		else:
    			print( "<h2><font color=lime>Ευχαριστώ πολύ για το ενδιαφέρον! Θα επικοινωνήσω μαζί σου άμεσα :-)</font></h2>" )
    			
    	sys.exit(0)
    Thank you! I beleive this is the simplest way of sending an email!
    What is now proved was once only imagined!
  10. #6
  11. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,280
    Rep Power
    13
    Originally Posted by partoj
    Have you verified that you can send mail using "sendmail" manually?

    If so, I would then troubleshoot this by printing out the exact command you're trying to use, and then check the output data and return code in your python code. Paste that and we can continue troubleshooting.
    Althought mail works i wish to use sndmail isntead becuase mail doesnt handle greek letters okwy.

    Please give me the command i should issue on my remote linuxjailed shell so to test if sendmail works.
    What is now proved was once only imagined!
  12. #7
  13. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,280
    Rep Power
    13
    Any help here please?
    What is now proved was once only imagined!

IMN logo majestic logo threadwatch logo seochat tools logo