Python Networking: Send Emails using smtplib

Here is a small application in Python for sending email messages via SMTP

=====================================================

#!/usr/bin/python
import smtplib

fromAddr = raw_input(‘From: ‘)
toAddr = raw_input(‘To: ‘)

Subject = raw_input(‘Subject: ‘)
Message = raw_input(‘Message: ‘)

Email = ‘Subject: ‘+Subject+’\n\n’+Message

Server = smtplib.SMTP(“BlackPearl”,25)
Server.sendmail(fromAddr, toAddr, Email)
print ‘Your Email has been sent to ‘, toAddr

====================================================

If your system has two users “root” and “leaf” you should have two email accounts like root@localhost and leaf@localhost (Assuming hostname to be localhost. Here in this example its BlackPearl)

Run using python email_smtp.py

To view the email type mail and type the email number to read it.

Advertisements

Leave a comment

Filed under Linux, Programming, Python

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s