Shell Dovecot email quota not parsing HTML

Hi,

We want all our user to get automated email notification when they are about to reach their quota.
In order to achieve this, we created the files below:
/usr/local/bin/quota-warning.sh
Code:
#!/bin/sh
#
# Purpose: Mail to user when his/her quota exceeds specified percentage.
# Reference: http://wiki2.dovecot.org/Quota/Configuration#Quota_warnings
#

PERCENT=$1
USER=$2
cat << EOF | /usr/local/libexec/dovecot/dovecot-lda -d $USER -o "plugin/quota=maildir::noenforcing"
From: no-reply@mydomain.co.uk
BCC: alert@mydomain.co.uk
Subject: Mailbox Quota Warning: ${PERCENT}% Full, ${USER}.

Hello,

This is a friendly email to inform you that the email account ${USER} is currently ${PERCENT}% full.

<strong>WHAT HAPPENS WHEN MY MAILBOX IS FULL?</strong>
If your mailbox becomes full on the server, you will stop receiving new emails. People who email you will usually receive an email informing them that their message was not delivered because your mailbox is full.

<strong>HOW CAN I CHECK MY MAILBOX QUOTA?</strong>
- Log into your webmail account here: https://mydomain.co.uk/webmail
- Your quota usage is shown on the home page in the lower left corner.

<strong>WHAT SHOULD I DO TO PREVENT MY MAILBOX TO BE FULL?</strong>
- Save large email attachments to your local computer.
- Delete draft emails no longer needed from your drafts folder.
- Remove attachments from sent emails in your sent folder.
- Delete sent emails no longer needed from your sent folder.

<strong>Note:</strong> Deleted email is sent to the bin/trash folder, which is included in your quota. To permanently delete email, empty the bin/trash folder.

<strong>NEED MORE HELP?</strong>
If you need further assistance in solving this issue, please login to https://mydomain.co.uk/support/ and log a ticket with our support department who will be happy to help.

<strong>WARNING:</strong> Do not ignore this message - if your mailbox quota exceeds 100% all incoming email will be rejected.

** THIS MESSAGE WAS AUTOMATICALLY CREATED BY MAIL DELIVERY SOFTWARE. **
EOF
/usr/local/etc/dovecot/conf.d/90-quota.conf
Code:
##
## Quota configuration.
##

# Note that you also have to enable quota plugin in mail_plugins setting.
# <doc/wiki/Quota.txt>

##
## Quota limits
##

# Quota limits are set using "quota_rule" parameters. To get per-user quota
# limits, you can set/override them by returning "quota_rule" extra field
# from userdb. It's also possible to give mailbox-specific limits, for example
# to give additional 100 MB when saving to Trash:

plugin {
  #quota_rule = *:storage=1G
  #quota_rule2 = Trash:storage=+100M
}

##
## Quota warnings
##

# You can execute a given command when user exceeds a specified quota limit.
# Each quota root has separate limits. Only the command for the first
# exceeded limit is excecuted, so put the highest limit first.
# The commands are executed via script service by connecting to the named
# UNIX socket (quota-warning below).
# Note that % needs to be escaped as %%, otherwise "% " expands to empty.

plugin {
  quota_warning = storage=95%% quota-warning 95 %u
  quota_warning2 = storage=90%% quota-warning 80 %u
  quota_warning3 = -storage=100%% quota-warning below %u # user is no longer over quota

}

# Example quota-warning service. The unix listener's permissions should be
# set in a way that mail processes can connect to it. Below example assumes
# that mail processes run as vmail user. If you use mode=0666, all system users
# can generate quota warnings to anyone.
service quota-warning {
  executable = script /usr/local/bin/quota-warning.sh
  user = dovecot
  unix_listener quota-warning {
    user = vmail
  }
}

##
## Quota backends
##

# Multiple backends are supported:
#   dirsize: Find and sum all the files found from mail directory.
#            Extremely SLOW with Maildir. It'll eat your CPU and disk I/O.
#   dict: Keep quota stored in dictionary (eg. SQL)
#   maildir: Maildir++ quota
#   fs: Read-only support for filesystem quota

plugin {
  #quota = dirsize:User quota
  #quota = maildir:User quota
  #quota = dict:User quota::proxy::quota
  #quota = fs:User quota
}

# Multiple quota roots are also possible, for example this gives each user
# their own 100MB quota and one shared 1GB quota within the domain:
plugin {
  #quota = dict:user::proxy::quota
  #quota2 = dict:domain:%d:proxy::quota_domain
  #quota_rule = *:storage=102400
  #quota2_rule = *:storage=1048576
}

plugin {
  quota = dict:User quota::proxy::quota
  quota_rule2 = Trash:storage=+100M
}

The emails are sent to the user is plan text showing all the html tags.
For example, I would expect
Code:
<strong>HOW CAN I CHECK MY MAILBOX QUOTA?</strong>
to show the text in bold in the email and not seeing the <strong> tags

Could anyone please advise how to get the html to work

Thank you
 
Use telnet to send a test HTML formated e-mail then modify your quota-warning.sh to represent the html tags

telnet mail.mydomain.co.uk 25

Code:
HELO testpc.domain.com
MAIL FROM: no-reply@mydomain.co.uk
RCPT TO: user@mydomain.co.uk
DATA

From: no-reply@mydomain.co.uk
BCC: alert@mydomain.co.uk
Subject: Mailbox Quota Warning


Mime-Version: 1.0;
Content-Type: text/html; charset="ISO-8859-1";
Content-Transfer-Encoding: 7bit;


<html>
<body>
<h2>An important link to look at!</h2>
Here's an <a href="https://forums.freebsd.org/threads/dovecot-email-quota-not-parsing-html.70114/">important link</a>
</body>
</html>
.
QUIT
 
Use telnet to send a test HTML formated e-mail then modify your quota-warning.sh to represent the html tags
Hi,

I know how to telnet but not how to send a test HTML formated e-mail.
Can you please show an example?
 
The example is in the above post. After you connect to your SMTP server type the code from the above replacing the e-mail addresses with your own e-mail address and test it.
 
Exactly You need to encode the e-mail you are sending, to tell the e-mail client (the user program that displays it) that the text is in HTML format. MIME is used for that.

But as a courtesy, you should also encode an alternate version of the same text without HTML formatting; some users (me included) prefer to read straight text, or don't even have a mail client capable of rendering HTML. Here is an example of a simple mail message that has been MIME'ed; there is a plain-text version in 7-bit US-ASCII, and a HTML version that prints its text in green.
Code:
    Content-Type: multipart/alternative;
     boundary="===============6433846379535083236=="
    MIME-Version: 1.0
    From: House Network Monitor <netmaster@example.com>
    To: Ralph at Home <ralphbsz@example.com>
    Subject: Test message

    --===============6433846379535083236==
    Content-Type: text/plain; charset="us-ascii"
    MIME-Version: 1.0
    Content-Transfer-Encoding: 7bit

    Message content.
    --===============6433846379535083236==
    Content-Type: text/html; charset="us-ascii"
    MIME-Version: 1.0
    Content-Transfer-Encoding: 7bit

    <FONT COLOR="GREEN">Message content.</FONT>
    --===============6433846379535083236==--
 
Back
Top