error while writing program to send mail.

Cameron Simpson cs at zip.com.au
Mon Sep 1 19:52:00 EDT 2014


On 02Sep2014 05:05, Om Prakash <torque.india at gmail.com> wrote:
>I am writing this program from 
>https://docs.python.org/2/library/email-examples.html
>
>but getting the error as
>
>singhom at debian:~/pythons$ python send_email.py
>Traceback (most recent call last):
>  File "send_email.py", 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.

Cheers,
Cameron Simpson <cs at zip.com.au>

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 leland.stanford.edu>



More information about the Python-list mailing list