[FRPythoneers] MIME attachment conversion and email module question

Erick Bodine erick at allocity.com
Fri Jan 24 13:40:22 MST 2003

The attachment displays properly in Outlook.
How would I go about checking the MIME headers?

I mean the "Encoders.encode_base64(msg)" step below.  Based on what you
are saying,  it would be possible to do this step ahead of time.

If there is a better way to do this I am more than open to suggestion.
Understanding MIME and how it works is not my strong-suite. The code

import smtplib, mimetypes
from email import Encoders
from email.Message import Message
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
outer = MIMEBase('multipart', 'mixed')
outer['Subject'] = sub
outer['To'] = to
outer['From'] = frum
outer['Body'] = "Something in the body of the message"
outer.preamble = 'You will NOT see this in a MIME-aware mail client'
outer.epilogue = ''
ctype, encoding = mimetypes.guess_type(self.afile)
if ctype == None or encoding != None:
    ctype = 'application/octet-stream'
maintype, subtype = ctype.split('/', 1)
if maintype == 'text':
    fp = open(self.afile)
    msg = MIMEText(fp.read(), _subtype=subtype)
    fp = open(self.afile, 'rb')
    msg = MIMEBase(maintype, subtype)
msg.add_header('Content-Disposition', 'attachment',
self.outer = outer
self.session = smtplib.SMTP(self.host)
self.session.sendmail(frum, to, self.outer.as_string(0))



-----Original Message-----
From: Rob Riggs [mailto:rob at pangalactic.org] 
Sent: Friday, January 24, 2003 1:18 PM
To: frpythoneers at lists.community.tummy.com
Subject: Re: [FRPythoneers] MIME attachment conversion and email module

I don't think OE's MIME functionality is broken.  Does the attachment 
display properly in other email clients?  What do your MIME headers look


What do you mean exactly by MIME conversion? Are you talking base64 
encoding? If so, then Python has a base64 module that might prove

It might be helpful to see the code you are using.  I've done a lot of 
work with generating MIME messages with Python, but not with the email 


Erick Bodine wrote:

>I am involved in testing an email server product and am sending large
>amounts of email+attachment in the course of that testing.  I have
>that MIME conversion of large attachments (1-10MB) is expensive in
>of cpu time, is there any way to do the conversion ahead of time?  
>I am sending email+attachment using the email module to construct the
>message.  When the email is opened in Outlook Express, the size of the
>message is correct, but the attachment does not show.  I am assuming
>this is because of broken MIME functionality in Outlook Express,
>This message sent by the FRPythoneers mailing list.
>Unsubscribe: echo unsubscribe |
FRPythoneers-request at lists.community.tummy.com
>URL: http://lists.community.tummy.com/mailman/listinfo/frpythoneers

This message sent by the FRPythoneers mailing list.
Unsubscribe: echo unsubscribe |
FRPythoneers-request at lists.community.tummy.com
URL: http://lists.community.tummy.com/mailman/listinfo/frpythoneers

More information about the FRPythoneers mailing list