Email attachments and text

Remco Boerma rboerma at ipn-ict.nl
Mon Dec 15 03:41:06 EST 2003


cartermark46 at ukmail.com (Mark Carter) wrote:
>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: me at mydomain.com" + '\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




More information about the Python-list mailing list