Send an email by commandline using python script

Today, I thought to write a script for sending an email by the command line . I selected “python” as the language . Below is the script to do the same.

# Humble Devassy
# 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:
body = body + line
server = smtplib.SMTP(‘localhost’)
server.sendmail(From, Toaddress,body)

print “%s-%s” %(From, Toaddress)
if __name__ == ‘__main__’:
print ” “

Ahhh…. U have to take care of python indentation.. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *