⬆️ ⬇️

Adding special offers to customers in emails using Zentyal + Postfix + alterMIME

Good afternoon, evening or night, it all depends on the time of day in which you happened to read my article.



The sales department required in correspondence with customers to send special offers by email without routine work. In a nutshell, set out what and how it happened.



Initial data:

- mail server based on Zentyal 5.0.1 (postfix + dovecot + openDKIM, etc.)

- alterMIME v0.3.10

- HTML template with a sentence.



I will immediately say thanks to the article Unified Dynamic Corporate Signature with the Postfix + alterMIME logo , as well as comments, from which it emphasized the main idea.

')

First of all, we will make changes in the master.cf file, namely:



Replace:



 smtp inet n - y - - smtpd 


On:



 smtp inet n - y - - smtpd -o content_filter=dfilt: dfilt unix - nn - - pipe flags=Rq user=filter argv=/etc/postfix/disclaimer.sh -f ${sender} -- ${recipient} 


Next, create a directory structure:



 useradd -r -c "Postfix Filters" -d /var/spool/filter filter mkdir /var/spool/filter mkdir /etc/postfix/disclaimer chown filter:filter /var/spool/filter chmod 750 /var/spool/filter 


Now the main thing is to create the executable file /etc/postfix/disclaimer.sh with the contents:



 #!/bin/bash #   INSPECT_DIR=/var/spool/filter #   sendmail SENDMAIL=/usr/sbin/sendmail #  email   DISCLAIMER_ADDRESSES=/etc/postfix/disclaimer/addresses EX_TEMPFAIL=75 EX_UNAVAILABLE=69 trap "rm -f in.$$" 0 1 2 3 15 cd $INSPECT_DIR || { echo $INSPECT_DIR does not exist; exit $EX_TEMPFAIL; } cat > in.$$ || { echo Cannot save mail to file; exit $EX_TEMPFAIL; } #    (       ) from_address=`grep "From:" in.$$ | cut -d "<" -f 2 | cut -d ">" -f 1 | sed 's/^From: //g' | awk '{print $1}' | cut -d "@" -f 2 | grep -v ^h= | grep -v ^To` to_dom=`echo $to_address |cut -d "@" -f 2` my_domain="example.org" #       if [ `grep -wi ^${from_address}$ ${DISCLAIMER_ADDRESSES}` ]; then #       if [ "$from_address" = "example.org" ]; then #    HTML  ContentTypeFirst=`grep -m 1 '^Content-Type: ' in.$$ | cut -d " " -f 2 | cut -d ";" -f 1` ContentTypeMixed=`grep -m 2 '^Content-Type: ' in.$$ | cut -d " " -f 2 | cut -d ";" -f 1 | tail -n 1` isHTML=true if [ "$ContentTypeFirst" = "" ] || [ "$ContentTypeFirst" = "text/plain" ]; then isHTML=false; fi if [ "$ContentTypeFirst" = "multipart/mixed" ] && [ "$ContentTypeMixed" = "text/plain" ]; then isHTML=false; fi if [ "$ContentTypeFirst" = "multipart/mixed" ] && [ "$ContentTypeMixed" != "text/html" ] && [ "$ContentTypeMixed" != "multipart/related" ] && [ "$ContentTypeMixed" != "multipart/alternative" ]; then isHTML=false; fi if $isHTML ; then /usr/bin/altermime --input=in.$$ \ --disclaimer=/etc/postfix/disclaimer/disclaimer.txt \ --disclaimer-html=/etc/postfix/disclaimer/disclaimer.html \ --xheader="X-Copyrighted-Material: Please visit https://www.example.org/privacy.htm" || \ { echo Message content rejected; exit $EX_UNAVAILABLE; } fi fi fi $SENDMAIL -oi "$@" < in.$$ exit $? 


Now in order:



DISCLAIMER_ADDRESSES - in this file we enter the addresses of the sales department, in principle, if you can automate your domain, an example is in the article from where I got the idea.



from_address, to_dom and my_domain - is required to create a filter, in order not to apply this rule to other departments and not to send letters with proposals to themselves.



disclaimer.html - html file with sentences, including pictures, etc.



In principle, if there is a desire, it is possible to modify to infinity, the main task for which it is necessary.



PS This solution could also be implemented through amavisd-new, but this idea had to be abandoned, since you cannot insert xheader into the body of the letter, but this is a topic for another article.

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



All Articles