[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
follows.

<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.close()
else:
    fp = open(self.afile, 'rb')
    msg = MIMEBase(maintype, subtype)
    msg.add_payload(fp.read())
    fp.close()
    Encoders.encode_base64(msg)
        
msg.add_header('Content-Disposition', 'attachment',
filename=self.afile)
outer.attach(msg)
        
self.outer = outer
...
...
self.session = smtplib.SMTP(self.host)
...
...
self.session.sendmail(frum, to, self.outer.as_string(0))

<CODE>

--ERick

-----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
question

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

like?

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

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 
module.

-Rob

Erick Bodine wrote:

>All,
>
>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
found
>that MIME conversion of large attachments (1-10MB) is expensive in
terms
>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,
>yes/no??
>
>--ERick
>_______________________________________________
>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