Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'subject:error': 0.03; 'here?': 0.09; 'msg': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:while': 0.09; 'python': 0.11; 'wrote': 0.14; "'rb')": 0.16; 'nameerror:': 0.16; 'prakash': 0.16; 'presume': 0.16; 'received:80.91.229.3': 0.16; 'received:97': 0.16; 'received:plane.gmane.org': 0.16; 'subject:program': 0.16; 'subject:send': 0.16; 'subject:writing': 0.16; 'variable': 0.18; 'file,': 0.19; 'starts': 0.20; 'import': 0.22; 'error': 0.23; 'large,': 0.24; 'sorry,': 0.24; 'defined': 0.27; 'header:X -Complaints-To:1': 0.27; "doesn't": 0.30; 'programming.': 0.30; 'code': 0.31; 'getting': 0.31; 'file': 0.32; 'quite': 0.32; 'text': 0.33; 'open': 0.33; 'url:python': 0.33; '(most': 0.33; 'plain': 0.33; 'skip:# 10': 0.33; 'could': 0.34; 'message.': 0.35; 'something': 0.35; 'but': 0.35; 'hi,': 0.36; 'url:org': 0.36; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'realize': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'called': 0.40; 'new': 0.61; 'simple': 0.61; 'name': 0.63; 'close': 0.67; 'anything.': 0.68; "'with'": 0.84; 'email addr:gmail.com"': 0.84; 'subject::': 0.85 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re:error while writing program to send mail. Date: Mon, 1 Sep 2014 20:02:01 -0400 (EDT) Organization: news.gmane.org References: <540502CD.8030209@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 97.73.240.32 X-Newsreader: PiaoHong.Usenet.Client.VIP:1.56 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 53 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1409616038 news.xs4all.nl 2864 [2001:888:2000:d::a6]:48460 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:77423 Om Prakash Wrote in message: > Hi, > > I am writing this program from > https://docs.python.org/2/library/email-examples.html > > but getting the error as > > singhom@debian:~/pythons$ python send_email.py > Traceback (most recent call last): > File "send_email.py", line 18, in > 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(fp.read()) > > fp.close This line doesn't do anything. If you want to close the file, you need some parens, Or you can use the 'with' form instead of open. > > me = "torque.india@gmail.com" > you = "oomprakash@gmail.com" > > msg['Subject'] = 'The contents of $s' % message Just what did you plan to use here? You never defined a variable called message. If you intended to use msg, I presume you realize it could be quite large, -- DaveA