Kirk Strauser wrote:
Kirk,On Tuesday 03 May 2005 15:30, J Cameron Cooper wrote:Look at the Python 'email' package: http://python.org/doc/lib/module-email.htmlYou'll need to use External Methods to use this module, or allow access to it so that you can use Python Scripts.That's what I was afraid of. I love Zope and Python (and am getting ready to write a magazine article about the two) but jumping through Pythonic hoops to do stuff that would be easy in DTML drives me nuts. Thanks for the pointer, though. I'd stumbled across that earlier, but had kept looking in search of something easier. Here is some to send email + attachement. I used it to send PDFs. Use it as a guide if you choose the external python method option. I think MimeWriter makes it easier. Best luck, David <code snippets> import sys, smtplib, MimeWriter, base64, StringIO, os, string, time <essential code> message = StringIO.StringIO() writer = MimeWriter.MimeWriter(message) writer.addheader('MIME-Version', '1.0') writer.addheader('Subject', 'Purchase Approved') # writer.addheader('To', '[EMAIL PROTECTED]' ) # get ready to send attachment writer.startmultipartbody('mixed') # start off with a text/plain part part = writer.nextpart() body = part.startbody('text/plain') body.write('Services Inc.\n') body.write('Office Transaction notice\n') body.write('\n') body.write('Order: ' + itemNumber + '\n') body.write(' Authorized by: ' + userID + ' ' + datetime + '\n') body.write(' Amount: ' + amount + '\n') body.write('\nSee attached') # ............................ # add PDF attachment # ............................ part = writer.nextpart() part.addheader('Content-Transfer-Encoding', 'base64') body = part.startbody('application/pdf; name=%s' % attachment) # pdf file body.write(base64.encodestring( pdf )) # finish off writer.lastpart() # .................................................. # send the mail # . if user supplied userid/password then deal w/it # .................................................. smtp = smtplib.SMTP(self.MailHost.smtp_host) if self.MailHost.smtp_userid: smtp.ehlo() smtp_userid64 = base64.encodestring(self.MailHost.smtp_userid) smtp.docmd("auth", "login " + smtp_userid64[:-1]) if self.MailHost.smtp_pass: smtp_pass64 = base64.encodestring( self.MailHost.smtp_pass) smtp.docmd(smtp_pass64[:-1]) #smtp.sendmail( from address, to address, message body) smtp.sendmail('[EMAIL PROTECTED]', '[EMAIL PROTECTED]', message.getvalue()) smtp.quit() </end essential code> Good luck, David |
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )