error while writing program to send mail.

Cameron Simpson cs at
Tue Sep 2 01:52:00 CEST 2014

On 02Sep2014 05:05, Om Prakash <torque.india at> wrote:
>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.

This problem is generic to almost any programming language: you have not 
defined the variable "message" before you try to use it in the format string.

In the example code, the variable is called "textfile" and is supposed to be 
the name of a file containing some message text. The example code does not 
define it; you need to do so.

After you sort that, you then have a ython problem: you have said "$s" in your 
format string, but the python "%" operator expected "%s" in the format string.

Sort these two things and see how things proceed.

Cameron Simpson <cs at>

Personally, I find blinking text on a page to be extraordinarily annoying and
my first instinct is to back up one page, right away.
         - William Barr <wbarr at>

More information about the Python-list mailing list