DevHeads.net

postfix add warning message for all external incoming emails

Hello Friends,
I would like to make postfix add a warning message for all external
incoming emails - Something like this at the top of each mail.

WARNING: This email originated outside of our organization. Do not
click any links or open any attachments unless you recognize the
sender and know the content is safe

How is this possible in postfix?

Thanks/DP

Comments

Re: postfix add warning message for all external incoming emails

By Bill Cole at 09/09/2018 - 20:22

It's not possible in Postfix itself.

This can be done in a milter. The MIMEDefang milter has a function to
add arbitrary MIME parts to a message before or after the existing
content and if you are up to writing a few lines of Perl and learning
how the MIME::Entity module works, you could even modify existing
plaintext and/or HTML parts.

Re: postfix add warning message for all external incoming emails

By Wietse Venema at 09/09/2018 - 19:38

Durga Prasad Malyala:
Yes.

<a href="http://www.postfix.org/postconf.5.html#smtpd_client_restrictions" title="http://www.postfix.org/postconf.5.html#smtpd_client_restrictions">http://www.postfix.org/postconf.5.html#smtpd_client_restrictions</a>
<a href="http://www.postfix.org/access.5.html" title="http://www.postfix.org/access.5.html">http://www.postfix.org/access.5.html</a>

smtpd_client_restrictions =
check_client_access cidr:/etc/postfix/client_access.cidr

/etc/postfix/client_access.cidr
# An "internal" source.
127.0.0.0/8 dunno
192.168.0.0/16 dunno
# Everyone else.
0.0.0.0/0 prepend WARNING: This email originated outside of our
organization. Do not click any links or open any attachments
unless you recognize the sender and know the content is safe.

I suppose lawyers love this. Otherwise I think it is useless.

Wietse

Re: postfix add warning message for all external incoming emails

By Bill Cole at 09/09/2018 - 20:34

Won't that just add a "WARNING:" RFC822 header to the message?

That would be more useless than the average boilerplate addition to
email, since very few users see arbitrary headers.

Re: postfix add warning message for all external incoming emails

By Viktor Dukhovni at 09/09/2018 - 19:54

Indeed, and the OP probably wanted to prepend message body content,
not a "WARNING:" header.

What I see much more often is organizations prepending "[EXTERNAL]"
to the subject lines of messages arriving from outside.

main.cf:
pcre = pcre:${config_directory}/
header_checks = ${pcre}header-checks.pcre
mime_header_checks = ... season to taste ...
nested_header_checks = ... typically best empty ...

header-checks.pcre:
if /^Subject:/
# Subject checks go here
/:(.*)/ REPLACE Subject: [EXTERNAL]$1
/^/ OK
endif

# Non-subject tests below
...

Re: postfix add warning message for all external incoming emails

By Richard Damon at 09/09/2018 - 13:22

On 9/9/18 1:35 PM, Durga Prasad Malyala wrote:
The bigger issue is that due to the way mail is structured, It can be
very difficult to actually do something like that. First, a message may
actually not have ANY text in it to add the message to, but might be
just something like a picture. Also, if the message is HTML formatted,
it can be very tricky to figure out how to insert text into it to be
displayed in a given manner.

You could add a text section to the beginning of the document with MIME,
but you would need to find out all the MUAs used internally, and make
sure you add the message in a way that they all handle reasonably (some
MUAs will take any multisection message and display all but the first
part as attachments, and don't handle email messages as attachments well.