Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #77426

Re: error while writing program to send mail.

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <torque.india@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'subject:error': 0.03; 'value,': 0.04; 'mrab': 0.05; 'string': 0.09; 'msg': 0.09; 'operator,': 0.09; 'subject:while': 0.09; 'python': 0.11; "'rb')": 0.16; 'be:': 0.16; 'headers.': 0.16; 'localhost': 0.16; 'nameerror:': 0.16; 'prakash': 0.16; 'subject:program': 0.16; 'subject:send': 0.16; 'subject:writing': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'trying': 0.19; 'starts': 0.20; 'import': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'sorry,': 0.24; 'defined': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'programming.': 0.30; 'code': 0.31; 'getting': 0.31; 'too.': 0.31; 'lot.': 0.31; 'file': 0.32; 'text': 0.33; 'open': 0.33; 'url:python': 0.33; '(most': 0.33; 'plain': 0.33; 'skip:# 10': 0.33; 'message.': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'thanks': 0.36; 'hi,': 0.36; 'url:org': 0.36; 'should': 0.36; 'message-id:@gmail.com': 0.38; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'new': 0.61; 'simple': 0.61; "you're": 0.61; 'name': 0.63; 'charset:windows-1252': 0.65; 'email addr:gmail.com"': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=bKVGVUATwvuzpWEsAVhAjsUkXLi1mcmI0hnAZBSR02Y=; b=i7UPyWDVBMbJhmz0/rXs/4NOjIRhGRohJznFLZs4K0HCWt0EReKhMmT9hUAToM1A5S R2j4TbLMGAtfaFxUBCWsLu6SDwNDWrPm5ZXponVUhUIqc892MPejyy1p1S3XUekROaG+ EN6FhtLMMJ64MwH6MLb6B5dS4oqqHhoQDGV4KVcz3n7yBPEuhAtKBXFYq9rIzKoMX1MI YDaQHrNCG9fQquxfGszc1Ag3gpEtYMVNZt7mcEd0HMAPaqaifsJnwbKmuPRxSb4NRvtr +Mb2ZTnRlk6jB2bPyBXyWxf/bUzfI7iulbvDCuh94eokXRI0zxuDDOPDr2IDnmBqpVIq evwQ==
X-Received by 10.66.66.6 with SMTP id b6mr5445311pat.51.1409619420403; Mon, 01 Sep 2014 17:57:00 -0700 (PDT)
Date Tue, 02 Sep 2014 06:26:57 +0530
From Om Prakash <torque.india@gmail.com>
User-Agent Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.0
MIME-Version 1.0
To python-list@python.org
Subject Re: error while writing program to send mail.
References <540502CD.8030209@gmail.com> <54050875.6060605@mrabarnett.plus.com>
In-Reply-To <54050875.6060605@mrabarnett.plus.com>
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.13704.1409619773.18130.python-list@python.org> (permalink)
Lines 64
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1409619773 news.xs4all.nl 2882 [2001:888:2000:d::a6]:39901
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:77426

Show key headers only | View raw


On 09/02/2014 05:29 AM, MRAB wrote:
> On 2014-09-02 00:35, Om Prakash wrote:
>> 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 <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(fp.read())
>>
>> fp.close
>
> That should be:
>
> fp.close()
>
>>
>> me = "torque.india@gmail.com"
>> you = "oomprakash@gmail.com"
>>
>> msg['Subject']  = 'The contents of $s' % message
>
> You're trying to use the format operator, but:
>
> 1. You never bound the name 'message' to a value, hence:
>
>     NameError: name 'message' is not defined
>
> 2. The format string contains '$s' instead of '%s'.
>
>> 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())
>> s.quit()
>>
>
Thanks a lot. will fix this and my overlooking of things too. :)

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: error while writing program to send mail. Om Prakash <torque.india@gmail.com> - 2014-09-02 06:26 +0530

csiph-web