Email attachments and text

M

Mark Carter

Section 12.2.13 (from the email module) gives examples of how to send
attachments with emails. The problem is, it does not explain how to
send text in the body of the message. One line of code that is gives
is:
outer.preamble = 'You will not see this in a MIME-aware mail
reader.\n'

So how do I arrange it so that the text *will* be seen?
 
J

Jp Calderone

Section 12.2.13 (from the email module) gives examples of how to send
attachments with emails. The problem is, it does not explain how to
send text in the body of the message. One line of code that is gives
is:
outer.preamble = 'You will not see this in a MIME-aware mail
reader.\n'

So how do I arrange it so that the text *will* be seen?

I recommend reading the documents linked from this page:

http://www.mhonarc.org/~ehood/MIME/

Once you have a solid understanding of MIME (particularly the multipart
type), using the email package should present no problems.

Jp
 
R

Remco Boerma

Section 12.2.13 (from the email module) gives examples of how to send
attachments with emails. The problem is, it does not explain how to
send text in the body of the message. One line of code that is gives
is:
outer.preamble = 'You will not see this in a MIME-aware mail
reader.\n'

So how do I arrange it so that the text *will* be seen?

a snippet of my code, i've add the html as plain text as well. STrip the
html codes are you're done.
All this is email body work, nothing else.
This seems to work, even with Outlook (and others :] )


self.msgbody = "Date: " +time.strftime("%a, %d %b %Y %H:%M:%S
+0100", time.gmtime()) + '\r\n'
self.msgbody += "Subject: " +subject+ '\r\n'
self.msgbody += "From: " +self.fr+ '\r\n'
self.msgbody += "To: "+self.to + '\r\n'
self.msgbody += "Sender: (e-mail address removed)" + '\r\n'
self.msgbody += "Content-Type: multipart/alternative;
boundary=SEPERATORLINEWICHSHOULDNEVEROCCURINREALTEXT" + '\r\n'
self.msgbody += "MIME-Version: 1.0" + '\r\n\r\n'
self.msgbody += """
--SEPERATORLINEWICHSHOULDNEVEROCCURINREALTEXT
Content-Type: text/plain

%(textbody)s

--SEPERATORLINEWICHSHOULDNEVEROCCURINREALTEXT
Content-Type: text/html

<html>%(htmlbody)s</html>

--SEPERATORLINEWICHSHOULDNEVEROCCURINREALTEXT--
""" % {'textbody':body,'htmlbody':body}

gr.
Remco
 
D

Dave Benjamin

--SEPERATORLINEWICHSHOULDNEVEROCCURINREALTEXT
^^^^^^^^^

Sorry to be pedantic, but please, this one just kills me.
Remember this; tell a friend:

there's *A* *RAT* in sepARATe

Thanks in advance. =)

PS. ''.join(map('WICH'.__getitem__, [3 * x for x in range(2)] + range(1, 4)))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top