error while writing program to send mail.

Om Prakash torque.india at
Tue Sep 2 01:35:41 CEST 2014


I am writing this program from

but getting the error as

singhom at debian:~/pythons$ python
Traceback (most recent call last):
   File "", line 18, in <module>
     msg['Subject']  = 'The contents of $s' % message
NameError: name 'message' is not defined

i know the error would be something simple and i am overlooking it, any 
help would be highly appreciated, I am sorry, but I am very new to 
python programming.

code starts here.
#/usr/bin/python2.7 -tt

## sending a simple text message using python.
import smtplib

from email.mime.text import MIMEText

# Open file for reading.
fp = open("message", 'rb')
# Create a plain text message.
msg = MIMEText(


me = "torque.india at"
you = "oomprakash at"

msg['Subject']  = 'The contents of $s' % message
msg['From'] = me
msg['To'] = you

# Send message thorugh localhost but don't include the envelope headers.

s = smtplib.SMTP('localhost')
s.sendmail(me, [you], msg.as_string())

More information about the Python-list mailing list