Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #77431
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: error while writing program to send mail. |
| Date | 2014-09-02 03:28 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <lu3dgo$t2s$1@dont-email.me> (permalink) |
| References | <mailman.13699.1409614555.18130.python-list@python.org> |
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 | Next — Previous in thread | Find similar | Unroll 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