I am trying to create an e-mail form that will send plain text, html, and up to two attachments. Without the HTML portion of things, I have everything working just fine, however, as mail clients need multipart/alternative specified in order to know whether to display either plain text or HTML, and then multipart/related specified in order to show multiple boundaries as one message, I am finding it impossible to get this working. I spent all day on it and have made headway but as there are no docs on this seemingly simple scenario, I have been unable to find a resolution.
This is my current statement. The issue is that the first dtml-boundary tag cannot be left blank or it defaults to making everything base64 encoded and the e-mail comes through as an attachment (the entire message). If I specify type="text/plain", etc. it inserts additional lines in the raw body of the email and thus it doesn't display in a mail client correctly (see below for examples).
Here is what I currently have.
<dtml-sendmail mailhost="MailHost">
To: <dtml-var primary_email>
<dtml-if "secondary_email!=None">
Cc: <dtml-var secondary_email>
</dtml-if>
From: <dtml-var email_from>
Subject: <dtml-var email_subject>
<dtml-mime type="text/plain" charset="us-ascii" encode="7bit" multipart="alternative"><dtml-var email_body_plain>
<dtml-boundary type="text/plain" charset="UTF-8" encode="7bit">
<dtml-mime type="text/html" charset="UTF-8" encode="7bit" multipart="related"><html><body><dtml-var email_body><br><br></body></html>
<dtml-boundary type_expr="REQUEST.get('file_type', attachment1.headers['Content-Type'] )" disposition="attachment" encode="base64" name_expr=attachment1.filename filename_expr=attachment1.filename><dtml-var expr="attachment1.read()"></dtml-mime>
</dtml-mime>
</dtml-sendmail>
This is what comes through in the raw email (pertinent section only):
--xx.xxx.xxx.xx.1230.13812.1592269201.208.191`
Content-Type: text/plain;
charset="UTF-8"
Content-Transfer-Encoding: 7bit
Mime-Version: 1.0
Content-Type: multipart/related;
boundary="xx.xxx.xxx.xx.1230.13812.1592269201.209.192"
--xx.xxx.xxx.xx.1230.13812.1592269201.209.192
This does not display correctly, however the following does (note that there must be the boundary and then no space before the Mime-Version but for the life of me I can't figure out how to accomplish this. I got it to work by editing the raw email by hand and testing it out in Thunderbird):
--xx.xxx.xxx.xx.1230.13812.1592269201.208.191
Mime-Version: 1.0
Content-Type: multipart/related;
boundary="69.164.211.16.1230.13812.1592269201.209.192"
--69.164.211.16.1230.13812.1592269201.209.192
Without the attachment, plain text and html work perfectly. Without the html portion, plain text and both a single attachment and/or two attachments work perfectly.