Send mail using python :

First install sendmail  utility in your linux machine
So that you no need to rely on any SMTP server :)


You need to Install sendmail. Enter the following command in the terminal:


  • sudo apt-get install sendmail 


    To restart, stop, start sendmail

  • /etc/init.d/sendmail restart
  • /etc/init.d/sendmail stop
  • /etc/init.d/sendmail start

  • Now your SMTP  Mail Transfer Agent (MTA) will be ready to rock

    If you want to send mail notification from your code all you need to do is import smtp lib
    in  smtplib.SMTP('localhost', 25)   
    Server name is 'localhost' now copy below code and run

    
    
    #!/usr/bin/python
    
    import smtplib
    
    from_id = 'sender@domain.com'
    to_id = ['receiver@domain.com','another_receiver@domain.com']
    
    mail_body = """From: From Person <naren>
    To: To Person <Reciver>
    Subject: This is SMTP mail sent using
    SMTP mail server located in same system(localhost)
    """
    
    try:
        smtpObj = smtplib.SMTP('localhost', 25)
        smtpObj.sendmail(from_id, to_id, mail_body)
        print "Sent email succefully"
    
    except SMTPException:
        print "Error: Mail Not sent"
    Want to try more Just try this link  http://www.doughellmann.com/PyMOTW/smtplib/