espenmn
(Espen)
1
Is it possible to use plonerestapi (or similar) to send a mail with a (small) attachement ‘from ajax’ ?
If yes, are there any docs / examples
By restapi, I am thinking about.
$.ajax({
url: '@@email-send',
type: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
mekell
(me-kell)
2
base64encode your file and add the encoded string in a MIME - Multipart message.
The following (PHP) code might be usefull:
caveat If you use Plone's REST API you won't be able to send multipart messages unless you patch it
plone/restapi/services/email_send/post.py prepends a message_intro to the actual message:
message = f"{message_intro} \\n {message}"
If you comment out line 108 the multipart message will work as expected.
sed -i \
'/^ message = f"{message_intro} \\n {message}"/ s/./#&/' \
/path/to/your/site-packages/plone/restapi/services/email_send/post.py
espenmn
(Espen)
3
Thanks. I ended up making a new restapi endpoint based on email send
mekell
(me-kell)
4
Here you'll find an minimal working example how to do it with fetch using the patched /@send-mail endpoint.