[Tutor] content disposition header: email module

nimrodx nimrodx at slingshot.co.nz
Wed Sep 6 12:38:36 CEST 2006


Hi Python Gurus,

I am trying to mail a txt file, then with another client I
get the email and extract the text file.
The email I send however, does not seem to turn out correctly.
The content dispositon header is there, but it seems to be in the wrong 
place and my email
client the text file just gets included in the message body, and the 
file name is not visible.

This is the code:

from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.MIMEImage import MIMEImage

   def attch_send(self):
        msg = MIMEMultipart()
        #msg.add_header("From", sender)
        #msg.add_header("To", recv)
        msg.add_header('Content-Disposition', 'attachment', 
filename='web-list.txt')
        msg.attach(MIMEText(file(os.path.join(save_dir, 
"web-list.txt")).read()))
        server = smtplib.SMTP('localhost')
        #server.set_debuglevel(1)
        server.sendmail(sender, recv, msg.as_string())
        server.quit()                             
                 


What is wrong with that?

I'd really appreciate your suggestions.

Thanks,

Matt


More information about the Tutor mailing list