Re: [exim] html vacation message

Página Inicial
Delete this message
Reply to this message
Autor: i6ghhisdw4rrkmgrjgzmjr
Data:  
Para: exim-users
Assunto: Re: [exim] html vacation message
Hi,

On 17/12/19 11:12 pm, Andrew McGlashan via Exim-users wrote:
> I've had vacation messages set up for years, but they have always been
> plain text content.
>
> How can I provide html content for the vacation message?
>
> Thanks and Kind Regards
> AndrewM



Okay, I solved this problem as follows:


Created a special user to do the vacation messages.


Added this to the .forward file of that special user

seen noerror pipe "/usr/local/bin/resend-vacation-email.sh"

Touch my-vacation-db file in the special user's home dir

Touch an empty .vacation file in the user whom is on vacation.


Here is the EDITED file used with the pipe:

# cat /usr/local/bin/resend-vacation-email.sh
#!/bin/bash

MESSAGE_ID=${2-no_message_id}

if [[ "${MESSAGE_ID}" = "no_message_id" ]]
then
    TMPFILE=$(mktemp)
else
    TMPFILE=/tmp/"${MESSAGE_ID}"
fi


BN_USER_HOME=$(basename "${HOME}")
TMPFILE="${TMPFILE}~${DOMAIN}~${BN_USER_HOME}"
env > "${TMPFILE}.env"

RESENT_BCC=
RESENT_TO=
REPLY_TO=no_reply_address@???
RESENT_FROM="${REPLY_TO}"

egrep -v 'dummy|^$' - > "${TMPFILE}.email-wrk"

RECEIVED=$(grep '^Received:' < "${TMPFILE}.email-wrk"|awk '{print $3}')

  SUBJECT=$(grep '^Subject:' < "${TMPFILE}.email-wrk"|awk -F~ '{print $1}')
RESENT_TO=$(grep '^Subject:' < "${TMPFILE}.email-wrk"|awk -F~ '{print $2}')
    TESTX=$(grep '^Subject:' < "${TMPFILE}.email-wrk"|awk -F~ '{print $3}')


[[ ${TESTX} = " special-random-string" ]] || exit 1

SDATEX_NOW=$(date +%s)
SDATEX_OLD=$(date +%s -d "-14 days")
[[ -f my-vacation-db ]] && {
    RECORDX=''
    RECORDX=$(
        grep "${RECEIVED}~${RESENT_TO:1}~1" < my-vacation-db | \
            awk -F~ '{print $3}'
    )
    if [[ ".${RECORDX}" = "." ]]
    then
            # add record for my own vacation database
            echo "${RECEIVED}~${RESENT_TO:1}~${SDATEX_NOW}" >> my-vacation-db
    else
            # exit if already sent vacation message in last 14 days
            [[ ${RECORDX} -gt ${SDATEX_OLD} ]] && exit 1
            sed -i "/${RECEIVED}~${RESENT_TO:1}~1/d" my-vacation-db
            echo "${RECEIVED}~${RESENT_TO:1}~${SDATEX_NOW}" >> my-vacation-db
    fi
}



(
    echo "Reply-To: ${REPLY_TO}"
    [[ -z "${RESENT_BCC}" ]] || echo "Resent-Bcc: ${RESENT_BCC}"
    echo "Resent-From: ${RESENT_FROM}"
    [[ -z "${RESENT_TO}" ]]  || echo "Resent-To:  ${RESENT_TO}"
    echo "Resent-Date: $(/bin/date -R)"
    echo "To: ${RESENT_TO:1}"
    echo "${SUBJECT}"
    [[ -f .vacation_special ]] && cat .vacation_special
) | tee "${TMPFILE}.new" | /usr/sbin/sendmail -ti


exit 0



And here is my exim4 config file:

# cat /etc/exim4/conf.d/transport/15_user_vacation
uservacation_transport:
driver = autoreply
file = $home/.vacation
file_expand
once = $home/.vacation.db
# to use a flat file instead of a db specify once_file_size
#once_file_size = 2K
once_repeat = 14d
#from = $local_part@$domain
from = no_reply_address@$domain
#to = $sender_address
#subject = "Re: $h_subject"
bcc = special_vacation@???
subject = "Re: $h_subject ~ $sender_address ~ special-random-string"



And this is the content of the html file for the emails:

# cat .vacation_special
Content-Type: multipart/alternative; boundary="--foo"

----foo
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Merry Christmas & Happy New Year!

We close on 5pm Friday, December 20 and our office re-opens Wednesday,
January 8, 2020

----foo
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
"http://www.w3.org/TR/REC-html40/strict.dtd">
<HTML>
<HEAD>
<TITLE>Christmas Message</TITLE>
<BODY>
<img src="https://example.com/Christmas%20Banner%201920x576.png"
alt="Christmas Message">
</BODY>
</HTML>

----foo--



Now, if the special user receives email that doesn't have the special
string in the subject line, then it is dropped. If it does have the
special string, then it continues and works out (and keeps track of) if
the vacation message has been sent in the last 14 days or not (resend
once per 14 days per sender).

The special file for vacation is common for the business (Christmas
clousre). A little tweaking and I can have personalized html files per
user in the one area of the special_vacation_use, such as:
user1.vacation_special
user2.vacation_special

- and then use the "${RECEIVED}" variable from the script with the file
name....



Kind Regards
AndrewM