Send an email by commandline using python script

Humble Devassy Chirammal Forums Python Programming Send an email by commandline using python script

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #1943 Reply
    Humble
    Keymaster

    Today, I thought to write a script for sending an email by the command line . This script will do the same.

    #!/usr/bin/python
    # Humble Devassy humble.devassy@gmail.com
    # This is a simple script to send an email
    “”" This is the script to send an email”"”
    import sys
    import smtplib
    
    From = raw_input(“From:”)
    Toaddress = raw_input(“To:”).split(‘,’)
    print “Enter message , Once you have entered the content exit with [Ctrl]+D”
    body = “”
    while 1:
        line = sys.stdin.readline()
        if not line:
           break
        body = body + line
        server = smtplib.SMTP(‘localhost’)
        server.sendmail(From, Toaddress,body)
        server.quit()
    
    print “%s-%s” %(From, Toaddress)
    if __name__ == ‘__main__’:
    print ” “
    
Viewing 1 post (of 1 total)
Reply To: Send an email by commandline using python script
Your information: