How to send mail with attachments to Plone using a template approach?

I read the official documents about sending letters from Plone using some templates, and it still works.

My question is: how to add attachments using a template?

+3
source share
3 answers

The MailHost.send command accepts both python (unicode) strings and email.Message objects. This means that you can use the python email package to create the correct MIME message with attachments.

The standard library includes an excellent page of examples ; any text can still be generated by templates, as in the documentation related to you.

+4
source

Use the Python email module.

Examples:

http://docs.python.org/library/email-examples.html

Composed messages can be passed to context.MailHost (MTA Zope).

In any case, it's better to create and send emails from the Python level instead of using the old sendmail DTML facade ... don't use it.

+3
source

This is my solution, maybe this is not the best:

create the DTML mime_file method in portal_skin / custom:

  <dtml-mime type="text/text; charset=utf-8" encode="7bit"> <dtml-var "text"> <dtml-boundary type="application/octet-stream" disposition="attachment" filename_expr="nomefile"><dtml-var "file"></dtml-mime> 

Call it (e.g. with Python Script) as:

 message = context.mime_file(file=a_file, text=message, nomefile='attach_name.pdf') context.MailHost.send(message, mTo, mFrom, mSubj) 

where a_file is the contents of the file.

inspired by:

http://www.zope.org/Members/visibleoffice/HowTo.2003-10-22.1455

This is a quick and convenient solution using Python scripts.

+1
source

Source: https://habr.com/ru/post/1380794/


All Articles