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


Groups > comp.lang.python > #77431

Re: error while writing program to send mail.

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From Denis McMahon <denismfmcmahon@gmail.com>
Newsgroups comp.lang.python
Subject Re: error while writing program to send mail.
Date Tue, 2 Sep 2014 03:28:24 +0000 (UTC)
Organization A noiseless patient Spider
Lines 33
Message-ID <lu3dgo$t2s$1@dont-email.me> (permalink)
References <mailman.13699.1409614555.18130.python-list@python.org>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
Injection-Date Tue, 2 Sep 2014 03:28:24 +0000 (UTC)
Injection-Info mx05.eternal-september.org; posting-host="66ffcfa4470a58bcddbdcd1913f98ab4"; logging-data="29788"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ivgHx1bzYD9OevWmzX2wqQy9HIPxkxgM="
User-Agent Pan/0.136 (I'm far too busy being delicious; GIT 926a150 git://git.gnome.org/pan2)
Cancel-Lock sha1:fOmonLlSwnHMXGOW6uQkgLZXqBo=
Xref csiph.com comp.lang.python:77431

Show key headers only | View raw


On Tue, 02 Sep 2014 05:05:41 +0530, Om Prakash wrote:

> fp = open("message", 'rb')

"message" here is a string literal

> fp.close

should be fp.close()

> msg['Subject']  = 'The contents of $s' % message

message here is a variable. The variable named message has not previously 
had a value assigned to it.
$s should be %s

If you want the subject to be the filename, then what you need to do is:

1) assign the filename to some variable
2) open the file using the variable that contains the filename
3) use the variable that contains the filename to generate the subject

eg (assuming suitable imports etc) and the message is in a text file 
called message.txt:
 
msgfile = "message.txt"
fp = open( msgfile, "r" )
msg = MIMEText(fp.read())
fp.close()
msg['Subject']  = 'The contents of %s' % msgfile

-- 
Denis McMahon, denismfmcmahon@gmail.com

Back to comp.lang.python | Previous | NextPrevious 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