Posts tagged: email

Creating images for HTML emails with GIMP

If you’re designing HTML emails (for instance, newsletters or other mails that are not created with a Mail User Agent), you will know that you have to use HTML 3.2 because of Outlook 2007 and its strange Word 2007 rendering. (By the way, I’d even extend Microsoft’s argument that Word is better for security reasons because it doesn’t understand scripts and suggest using Word 2007 as the default browser for every computer.)

In Word/Outlook 2007 Background images are only accepted in this format:

<body background="URI to image, may be cid: for attached images>

But this is no news. For me, it became really strange when I used GIMP in Linux to create an image that was intended as a background for an HTML email message.

Word is designed for printing. Are emails too?

I created an image with 10.000 px width where the real graphical content was 700 px wide, filled up with white space. Then I wrote:

<body background="cid:img">
<table background="cid:img" cellspacing="0" cellpadding="0">

Sending this to Outlook 2007, it was all OK but the graphical content was much more than 600 px wide.

After playing around, I had the idea that this problem could be related to printing and DPI settings in some way. So I found out that GIMP creates images with 72 dpi per default (you can’t see this except in the images headers because the size in pixels is always the same). For more information about dpi, resolution and when its use makes sense (or not), see this German article: Dpi, Missverständnisse und Erklärung. Then, Outlook tries to render this image on the “printed” screen where the email is displayed (remember, Outlook uses Word and Word is a text processor, not an Internet browser) and so rescales it to get 96 dpi.

The solution: Open GIMP, load the image, set it to 96 dpi and save it again. You won’t note a difference, but Outlook 2007 does — it should work now (as long as users don’t change their default Windows dpi setting, see link above).

Of course, Microsoft, Outlook, Outlook Express, Office, Word, Internet Explorer, and all other trademarks and registered trademarks are properties of their respective owners. GIMP is free software.

Using ClamAV and SpamAssassin with Postfix (without Amavis)

Many people use AMaViS or amavisd-new to combine Postfix with ClamAV and SpamAssassin. However, Amavis takes huge amounts of CPU time and memory. Also, it’s quite slow and difficult to configure, so another solution without Amavis would be interesting.

In this article, I will only discuss server-wide solutions without procmail because it can’t be used with virtual domain mailboxes.

It’s possible to use a shell script that calls ClamAV and SpamAssassin as a Postfix content filter:

/opt/mail-scanner

#!/bin/sh

EX_OK=0
EX_BOUNCE=69
EX_DEFER=75

SENDMAIL="/usr/sbin/sendmail -G -i"

SPAM_DIR=/home/mailscan/spam
VIRUS_DIR=/home/mailscan/viruses

function cleanup {
for fname in ${tmpfile[@]}
do
rm -f $fname
done
}

for ((i=0;i&lt;2;i++))
do
fname=`mktemp -p /tmp mail-scanner.XXXXXXXX`
if [ "$?" != 0 ]; then
logger -s -p mail.warning -t scanner "Unable to create temporary file."
exit $EX_DEFER
fi
tmpfile[$i]=$fname
trap cleanup EXIT TERM
done

cat &gt;${tmpfile[0]}

# check for viruses

clamdscan - &lt;${tmpfile[0]} &gt;${tmpfile[1]}
return="$?"
if [ "$return" = 1 ]; then
virus=`grep FOUND ${tmpfile[1]}`
logger -p mail.info "Message rejected by ClamAV: $virus"
mv ${tmpfile[0]} `mktemp -p $VIRUS_DIR virus.XXXXXXXX`
exit $EX_OK             # discard (exit without re-injecting)
elif [ "$return" != 0 ]; then
logger -s -p mail.warning -t scanner "Temporary ClamAV failure (clamdscan returned $return)"
exit $EX_DEFER
fi

# check for spam

spamc -x &lt;${tmpfile[0]} &gt;${tmpfile[1]}
return="$?"
if [ "$return" = 1 ]; then
logger -p mail.info "Message rejected by SpamAssassin"
mv ${tmpfile[0]} `mktemp -p $SPAM_DIR spam.XXXXXXXX`
exit $EX_OK             # discard (exit without re-injecting)
elif [ "$return" != 0 ]; then
logger -s -p mail.warning -t scanner "Temporary SpamAssassin failure (spamc returned $return)"
exit $EX_DEFER
fi

# deliver

$SENDMAIL "$@" &lt;${tmpfile[1]}
exit $?

All you need is to copy this script to a location, let’s say /opt or /usr/local/bin and then edit the master.conf file of your Postfix so that:

  • the smtp service takes a content filter service (called “scanner” here, but you may use any name):
    smtp  inet  n  -  -  -  -  smtpd -o content_filter=scanner:dummy
  • the content filter service is defined:
    scanner   unix  -       n       n       -       5       pipe
      flags=Rq user=mailscan argv=/opt/mail-scanner -f $sender -- $recipient

Image | WordPress Themes