sending attachments
hi, is it possible to send mails with attachments using Zope MailHost?? if so,...how do u achieve it? __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
--On 28. Mai 2005 06:47:14 -0700 Varun Parange <varunsemail@yahoo.com> wrote:
hi,
is it possible to send mails with attachments using Zope MailHost??
MailHost is for sending out emails but not for composing emails in any way. Look at <dtml-mime> or Python's 'email' module (-> Python Library Ref). -aj
Am Samstag, den 28.05.2005, 06:47 -0700 schrieb Varun Parange:
hi,
is it possible to send mails with attachments using Zope MailHost?? if so,...how do u achieve it?
If you have a simple product like this: EmailTools/__init__.py ------------------- contents --------------------------------- from AccessControl import allow_module, allow_class, allow_type from AccessControl import ModuleSecurityInfo, ClassSecurityInfo from email.MIMEText import MIMEText from email.MIMEMultipart import MIMEMultipart from email.MIMEBase import MIMEBase from email.Header import Header from MailCrypt import signmail from email.Encoders import encode_base64 allow_class(BlockFormatter) allow_class(MIMEBase) allow_class(MIMEText) allow_class(MIMEMultipart) allow_class(Header) allow_class(signmail) allow_class(encode_base64) --------------------------------------------------------------- You can send mails with attachment like this: from Products.EmailTools import MIMEText,MIMEBase,MIMEMultipart,Header,encode_base64 msg=MIMEMultipart() inner=MIMEText(mailtext,_charset='iso-8859-1') msg.attach(inner) msg.add_header('Subject',str(Header(subject,"iso-8859-1"))) # now the attachments: for obj in context.attachments.objectValues('File'): mt,st=obj.content_type.split("/") p=MIMEBase(mt,st) p.set_payload(str(obj)) p.add_header('content-disposition', 'attachment', filename=obj.getId()) encode_base64(p) msg.attach(p) # now you are ready to send the mail like this: context.YourMailHost.send(msg.as_string(), mfrom="Foobar <foo@bar.com>", mto=["Someone <someone@whereever.com>"])
Varun Parange wrote:
hi,
is it possible to send mails with attachments using Zope MailHost?? if so,...how do u achieve it?
I use DTML method to send .csv-file as attachment: <dtml-sendmail mailhost="MailHost"> To: <dtml-var msgTo> From: <dtml-var msgFrom> Subject: <dtml-var msgSbj> <dtml-mime type="text/plain" encode="7bit"> <dtml-var msgBody> <dtml-boundary type="text/csv" disposition="attachment" encode="base64" filename="addresses.csv"><dtml-var expr="msgFile"></dtml-mime> </dtml-sendmail> I hope it helps.
participants (4)
-
Andreas Jung -
Tino Wildenhain -
Varun Parange -
Vital Lobachevsky