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


Groups > comp.lang.python > #77420

error while writing program to send mail.

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3a.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.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'python.': 0.02; 'subject:error': 0.03; 'msg': 0.09; 'subject:while': 0.09; 'python': 0.11; "'rb')": 0.16; 'headers.': 0.16; 'localhost': 0.16; 'nameerror:': 0.16; 'subject:program': 0.16; 'subject:send': 0.16; 'subject:writing': 0.16; 'starts': 0.20; 'import': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'sorry,': 0.24; 'defined': 0.27; 'programming.': 0.30; 'code': 0.31; 'getting': 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; 'hi,': 0.36; 'url:org': 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; 'name': 0.63; '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 :content-type:content-transfer-encoding; bh=D/YVlxuVH7UqWjk0mL+IP+5UeSVMOb9s/0Rh/LqgXuo=; b=b8caZ/fgr8cqE8UNQSuHMR/SCn1d4DDvRA24jvxkVs/J3rYsZBxGG2wLIHp4PEcYrv S/5i6GZSiJg8ITrWJOcmpoi7igS/MKafkamuQIvhth2bnhbvzkx+Rk7DNk9jKV0dQeXW AhhVfoGc12K7MqgRZtY3UmzZJocLHIey2Co5okpAKbE3hTzgCHhuJbMq/yGwNl5IVTBr vM8lmzgUMXGoDXzMNuciowrQXR0FMxDbdLI0xoiDogCYGq6PTjgyYRWd715De34r43zQ fwdsk4C9TQFzpBRRdrN8/lSZ9i7CykqEaCRqaNdSpoKiR41IGMDyyt0QwMawwjDibvO/ cxVg==
X-Received by 10.66.176.97 with SMTP id ch1mr6818694pac.101.1409614547165; Mon, 01 Sep 2014 16:35:47 -0700 (PDT)
Date Tue, 02 Sep 2014 05:05:41 +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 error while writing program to send mail.
Content-Type text/plain; charset=utf-8; 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.13699.1409614555.18130.python-list@python.org> (permalink)
Lines 46
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1409614555 news.xs4all.nl 2834 [2001:888:2000:d::a6]:41090
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:77420

Show key headers only | View raw


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

me = "torque.india@gmail.com"
you = "oomprakash@gmail.com"

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())
s.quit()

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


Thread

error while writing program to send mail. Om Prakash <torque.india@gmail.com> - 2014-09-02 05:05 +0530
  Re: error while writing program to send mail. Denis McMahon <denismfmcmahon@gmail.com> - 2014-09-02 03:28 +0000

csiph-web