|
|
|
|
wchr
()
|
|
||||||||||||
|
hi,
i am not sure, if this is the right place for my problem, because i think it could be a pure python email problem. i try to send pdf files stored in archetypes file fields via python email module. the resulting email looks fine, but if i open one of these pdf attachment in my thunderbird, it is somehow corrupted - it opens in acrobat but only shows white/empty space. i use plone 3.3.1 on RHEL. first i thought that the reason for this corruption could be caused by incorrect file data. data in archetypes file field is wrapped in acquisition and this pdata thing. but i think i solved that by using: filedata = str(aq_base(filedata)). i tried it with both original ATFile and with custom filefields. ------------------------------------------------------------------------------ # 1) just return pdf data to browser for testing purposes from Acquisition import aq_base archobj = ploneroot['testfile.pdf'] # later i use a sequence of fieldid = 'file' # (archetypesobj,filefieldid) tuples filefield = archobj.getField(fieldid) mimetype = filefield.getContentType(archobj) filename = filefield.getFilename(archobj) filedata = filefield.getRaw(archobj).data filedata = str(aq_base(filedata)) self.REQUEST.RESPONSE.setHeader('Content-Type','application/pdf') return filedata # result: pdf opens in acrobat, everything looks wonderful ------------------------------------------------------------------------------ # 2) try to email this (plain text mail with attachment): from email.Header import make_header from email.MIMEMessage import Message from email.MIMEBase import MIMEBase from email.MIMEMultipart import MIMEMultipart from email.MIMEText import MIMEText import smtplib archobj = ploneroot['testfile.pdf'] fieldid = 'file' messagetext = 'Test text' subject = 'Test Subject' mfrom = '[hidden email]' mto = '[hidden email]' # create message msg = MIMEMultipart('related') msg.attach(MIMEText(messagetext, 'plain', 'utf-8')) msg.preamble = subject subject = unicode(subject, 'utf-8') msg['Subject'] = str(make_header([(subject, 'utf-8')])) msg['Subject'] = subject msg['From'] = mfrom msg['To'] = mto # attach pdf filefield = archobj.getField(fieldid) mimetype = filefield.getContentType(archobj) filename = filefield.getFilename(archobj) filedata = filefield.getRaw(archobj).data filedata = str(aq_base(filedata)) maintype, subtype = mimetype.split('/', 1) subpart = MIMEBase(maintype, subtype) subpart.set_payload(filedata) subpart.add_header('Content-Disposition', 'attachment', filename=filename) msg.attach(subpart) # send msg server = smtplib.SMTP('mx.y.at') server.sendmail(mfrom, mto, msg.as_string()) # result as explained above: the attachment file is somehow corrupted, # the email message source looks like: ------------------------------------------------------------------------------ From - Tue Nov 03 11:23:29 2009 Return-path: <xxx> Envelope-to: xxx Delivery-date: Tue, 03 Nov 2009 11:23:20 +0100 Received: from [x.x.x.x] (helo=xxx) by xxx with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from <xxx>) id 1N5GXj-0001UX-SO for xxx; Tue, 03 Nov 2009 11:23:20 +0100 Received: from xxx ([x.x.x.x]) by xxx with esmtp (Exim 4.69) (envelope-from <xxx>) id 1N5GXf-0007ru-Nf for xxx; Tue, 03 Nov 2009 11:23:15 +0100 Content-Type: multipart/related; boundary="===============5330435108290451438==" MIME-Version: 1.0 To: [hidden email] From: [hidden email] Message-Id: <E1N5GXf-0007ru-Nf@xxx> Date: Tue, 03 Nov 2009 11:23:11 +0100 Test Subject --===============5330435108290451438== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 VGVzdCB0ZXh0CnNlY29uZCBsaW5l --===============5330435108290451438== Content-Type: application/pdf MIME-Version: 1.0 Content-Disposition: attachment; filename="xxx.pdf" %PDF-1.4 %���� 28 0 obj <</Linearized 1/L 86729/O 30/E 17799/N 5/T 86122/H [ 616 275]>> endobj xref 28 16 0000000016 00000 n 0000000891 00000 n 0000000971 00000 n 0000001106 00000 n 0000001268 00000 n 0000001803 00000 n 0000002335 00000 n 0000002777 00000 n 0000003019 00000 n 0000003267 00000 n 0000003343 00000 n 0000003598 00000 n 0000005698 00000 n 0000005732 00000 n 0000008401 00000 n 0000000616 00000 n trailer <</Size 44/Prev 86111/Root 29 0 R/Info 27 0 R/ID[<1553A717E451F81171F09829CE3F8EF4><54ED48EF58E1784FA0D3075DF7F654E0>]>> startxref 0 %%EOF 43 0 obj<</Length 188/Filter/FlateDecode/I 215/L 199/S 133>>stream [snipped......................................................................] 0000082066 00000 n 0000082101 00000 n 0000082125 00000 n 0000082202 00000 n 0000085853 00000 n trailer <</Size 28>> startxref 116 %%EOF --===============5330435108290451438==-- ------------------------------------------------------------------------------ best /wolfie ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Plone-Users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/plone-users |
||||||||||||||
|
|
wchr
()
|
|
||||||||||||
|
hi,
ok, solved that now. what a mess: when i had solved the problem with str(aq_base(filedata)) to get the correct file data i inserted another bug, which i didn´t have before. the correct code to mail archetypes filefield pdfs with python email: encoders.encode_base64(subpart) # was missing ---------------------------------------------------------- from email.Header import make_header from email.MIMEMessage import Message from email.MIMEBase import MIMEBase from email.MIMEMultipart import MIMEMultipart from email.MIMEText import MIMEText import smtplib archobj = ploneroot['testfile.pdf'] fieldid = 'file' messagetext = 'Test text' subject = 'Test Subject' mfrom = '[hidden email]' mto = '[hidden email]' # create message msg = MIMEMultipart('related') msg.attach(MIMEText(messagetext, 'plain', 'utf-8')) msg.preamble = subject subject = unicode(subject, 'utf-8') msg['Subject'] = str(make_header([(subject, 'utf-8')])) msg['Subject'] = subject msg['From'] = mfrom msg['To'] = mto # attach pdf filefield = archobj.getField(fieldid) mimetype = filefield.getContentType(archobj) filename = filefield.getFilename(archobj) filedata = filefield.getRaw(archobj).data filedata = str(aq_base(filedata)) maintype, subtype = mimetype.split('/', 1) subpart = MIMEBase(maintype, subtype) subpart.set_payload(filedata) encoders.encode_base64(subpart) subpart.add_header('Content-Disposition', 'attachment', filename=filename) msg.attach(subpart) # send msg server = smtplib.SMTP('mx.y.at') server.sendmail(mfrom, mto, msg.as_string()) ---------------------------------------------------------- best /wolfie wchr schrieb: > hi, > i am not sure, if this is the right place for my problem, because i > think it could be a pure python email problem. > > i try to send pdf files stored in archetypes file fields via python > email module. the resulting email looks fine, but if i open one of > these pdf attachment in my thunderbird, it is somehow corrupted - > it opens in acrobat but only shows white/empty space. i use > plone 3.3.1 on RHEL. > > first i thought that the reason for this corruption could be > caused by incorrect file data. data in archetypes file field is > wrapped in acquisition and this pdata thing. but i think i solved > that by using: filedata = str(aq_base(filedata)). > > i tried it with both original ATFile and with custom filefields. > > ------------------------------------------------------------------------------ > > # 1) just return pdf data to browser for testing purposes > > from Acquisition import aq_base > > archobj = ploneroot['testfile.pdf'] # later i use a sequence of > fieldid = 'file' # (archetypesobj,filefieldid) tuples > > filefield = archobj.getField(fieldid) > mimetype = filefield.getContentType(archobj) > filename = filefield.getFilename(archobj) > filedata = filefield.getRaw(archobj).data > filedata = str(aq_base(filedata)) > self.REQUEST.RESPONSE.setHeader('Content-Type','application/pdf') > return filedata > > # result: pdf opens in acrobat, everything looks wonderful > > ------------------------------------------------------------------------------ > > # 2) try to email this (plain text mail with attachment): > > from email.Header import make_header > from email.MIMEMessage import Message > from email.MIMEBase import MIMEBase > from email.MIMEMultipart import MIMEMultipart > from email.MIMEText import MIMEText > import smtplib > > archobj = ploneroot['testfile.pdf'] > fieldid = 'file' > > messagetext = 'Test text' > subject = 'Test Subject' > mfrom = '[hidden email]' > mto = '[hidden email]' > > # create message > > msg = MIMEMultipart('related') > msg.attach(MIMEText(messagetext, 'plain', 'utf-8')) > msg.preamble = subject > subject = unicode(subject, 'utf-8') > msg['Subject'] = str(make_header([(subject, 'utf-8')])) > msg['Subject'] = subject > msg['From'] = mfrom > msg['To'] = mto > > # attach pdf > > filefield = archobj.getField(fieldid) > mimetype = filefield.getContentType(archobj) > filename = filefield.getFilename(archobj) > filedata = filefield.getRaw(archobj).data > filedata = str(aq_base(filedata)) > maintype, subtype = mimetype.split('/', 1) > subpart = MIMEBase(maintype, subtype) > subpart.set_payload(filedata) > subpart.add_header('Content-Disposition', 'attachment', filename=filename) > msg.attach(subpart) > > # send msg > > server = smtplib.SMTP('mx.y.at') > server.sendmail(mfrom, mto, msg.as_string()) > > # result as explained above: the attachment file is somehow corrupted, > # the email message source looks like: > > ------------------------------------------------------------------------------ > > From - Tue Nov 03 11:23:29 2009 > Return-path: <xxx> > Envelope-to: xxx > Delivery-date: Tue, 03 Nov 2009 11:23:20 +0100 > Received: from [x.x.x.x] (helo=xxx) > by xxx with esmtps (TLSv1:AES256-SHA:256) > (Exim 4.63) > (envelope-from <xxx>) > id 1N5GXj-0001UX-SO > for xxx; Tue, 03 Nov 2009 11:23:20 +0100 > Received: from xxx ([x.x.x.x]) > by xxx with esmtp (Exim 4.69) > (envelope-from <xxx>) > id 1N5GXf-0007ru-Nf > for xxx; Tue, 03 Nov 2009 11:23:15 +0100 > Content-Type: multipart/related; > boundary="===============5330435108290451438==" > MIME-Version: 1.0 > To: [hidden email] > From: [hidden email] > Message-Id: <E1N5GXf-0007ru-Nf@xxx> > Date: Tue, 03 Nov 2009 11:23:11 +0100 > > Test Subject > --===============5330435108290451438== > Content-Type: text/plain; charset="utf-8" > MIME-Version: 1.0 > Content-Transfer-Encoding: base64 > > VGVzdCB0ZXh0CnNlY29uZCBsaW5l > > --===============5330435108290451438== > Content-Type: application/pdf > MIME-Version: 1.0 > Content-Disposition: attachment; filename="xxx.pdf" > > %PDF-1.4 > %���� > 28 0 obj <</Linearized 1/L 86729/O 30/E 17799/N 5/T 86122/H [ 616 275]>> > endobj > > xref > 28 16 > 0000000016 00000 n > 0000000891 00000 n > 0000000971 00000 n > 0000001106 00000 n > 0000001268 00000 n > 0000001803 00000 n > 0000002335 00000 n > 0000002777 00000 n > 0000003019 00000 n > 0000003267 00000 n > 0000003343 00000 n > 0000003598 00000 n > 0000005698 00000 n > 0000005732 00000 n > 0000008401 00000 n > 0000000616 00000 n > trailer > <</Size 44/Prev 86111/Root 29 0 R/Info 27 0 > R/ID[<1553A717E451F81171F09829CE3F8EF4><54ED48EF58E1784FA0D3075DF7F654E0>]>> > startxref > 0 > %%EOF > > 43 0 obj<</Length 188/Filter/FlateDecode/I 215/L 199/S 133>>stream > > [snipped......................................................................] > > 0000082066 00000 n > 0000082101 00000 n > 0000082125 00000 n > 0000082202 00000 n > 0000085853 00000 n > trailer > <</Size 28>> > startxref > 116 > %%EOF > > --===============5330435108290451438==-- > > ------------------------------------------------------------------------------ > > best > /wolfie > > ------------------------------------------------------------------------------ > Come build with us! The BlackBerry(R) Developer Conference in SF, CA > is the only developer event you need to attend this year. Jumpstart your > developing skills, take BlackBerry mobile applications to market and stay > ahead of the curve. Join us from November 9 - 12, 2009. Register now! > http://p.sf.net/sfu/devconference > _______________________________________________ > Plone-Users mailing list > [hidden email] > https://lists.sourceforge.net/lists/listinfo/plone-users ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Plone-Users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/plone-users |
||||||||||||||
| Free Embeddable Forum Powered by Nabble | Help |