I've set up a postfix mail server for my local network, that uses Postmark as smarthost. This actually works fine. But my Canon printer/copier sends mails without a mail body, but with attachment only.

This gives an error on the Postmark side: ErrorCode: '300', Message: 'Provide either email TextBody or HtmlBody or both.'.

Therefore I'd like to add a rule to my postfix to add a TextBody to the mail if it is missing, before forwarding to the smarthost. Any ideas?

  • 2
    I'd consider this as a bug in the Postmark, because MIME email which consists only of one "attachment" (non-text) file is perfectly fine email according to the standard. Tried to ask their support? Aug 31, 2021 at 14:23
  • 1
    Postfix supports milter and filter interfaces, you might find a good starting point for your script by searching for filters/milters written in the language of your choice. However, please edit your question to include a sample mail (abbreviate the attachment), for a few special cases where the headers are already almost-suitable there may be a simpler method using postfix built-ins.
    – anx
    Aug 31, 2021 at 17:00
  • @NikitaKipriyanov I did not even try to reach their support, because I've found this article beforehand: postmarkapp.com/support/article/… Probably it's not a bug, it's a feature ;-)
    – Caleb
    Sep 1, 2021 at 11:46

1 Answer 1


I've had the same problem with Postmark for some emails in a specific from/to pair. Using a postfix mail server, I used the disclaimer function in altermime to copy the subject line into the body, and applied some "if" logic so that altermime only ran when the email was from/to the specified addresses.

There's plenty of articles around of how to setup altermime, here's one of them: https://www.howtoforge.com/how-to-automatically-add-a-disclaimer-to-outgoing-emails-with-altermime-postfix-on-debian-squeeze

The article above is for Debian, but also largely works on RedHat derivatives. You'll need to install the program itself using dnf (or yum) and using the EPEL repository.

If you just want a static body (like you'd have with a disclaimer) then there's nothing else to do other than maybe apply some if logic if you don't want the text applied to every email.

If you want to add the subject line into the body, then the trick here is to output the subject line to a temporary file and then use that file as the disclaimer file in the script.

Like this:

Grab the subject line, and output it to a temporary file:

subject=`grep -m 1 "Subject:" in.$$ | cut -d "<" -f 2 | cut -d ">" -f 1 | cut -d " " -f 2-`
echo -e "\r\n$subject\r\n" >sub.$$

Then where the script needs a filename, just use sub.$$, e.g.

/usr/bin/altermime --input=in.$$ \
                   --disclaimer=sub.$$ \
                   --disclaimer-html=sub.$$ \
                   --xheader="X-SpecialContent-Header: TextAdded" || \
                     { echo Message content rejected; exit $EX_UNAVAILABLE; }

Finallly, don't forget to remove the temporary file - there's a line at the top of the script that removes the input file, just expand that line to remove the sub.$$ file:

trap "rm -f in.$$ sub.$$" 0 1 2 3 15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.