Hello fellow server enthusiasts! Today, I'd like to share a solution to a common request I often come across: setting up an email server to automatically add signatures to user emails. Specifically, we'll look at the Postfix SMTP server running on Ubuntu Server 16.04, and how to integrate signatures using altermime.
Step-by-Step Guide to Adding Signatures with Postfix and Altermime
1. Pre-requisites
- Configured and operational SMTP Postfix server.
- Ubuntu Server 16.04 OS.
2. Switch to Superuser Mode
sudo su
3. Update and Install Necessary Packages
First, ensure your package list is updated.
apt update
Then, install altermime
.
apt install altermime
4. Configuration
- Add a dedicated user for altermime:
useradd -r -c "Postfix Filters" -d /var/spool/filter filter
- Set up a directory with the correct permissions:
mkdir /var/spool/filter chown filter:filter /var/spool/filter/ chmod 755 /var/spool/filter/
5. Implement Mail Processing Script
nano
, create your mail processing script:nano /etc/postfix/disclaimer
with the following content:
#!/bin/sh # Localize these. INSPECT_DIR=/var/spool/filter SENDMAIL=/usr/sbin/sendmail DISCLAIMERS=/etc/postfix/disclaimers # Exit codes from <sysexits.h> EX_TEMPFAIL=75 EX_UNAVAILABLE=69 # Clean up when done or when aborting. trap "rm -f in.$$" 0 1 2 3 15 # Start processing. 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 -m 1 "From:" in.$$ | cut -d "<" -f 2 | cut -d ">" -f 1` from_address=`echo "$from_address" | sed "s/From: //g"` if [ -f $DISCLAIMERS/$from_address ] ; then /usr/bin/altermime --input=in.$$ \ --disclaimer=$DISCLAIMERS/${from_address} \ --disclaimer-html=$DISCLAIMERS/${from_address} || \ { echo Message content rejected; exit $EX_UNAVAILABLE; } fi $SENDMAIL -oi "$@" <in.$$ exit $?
This script will manage the email processing and integration of signatures based on sender addresses.
6. Permissions and Storage
After finalizing the script, set the correct permissions:
chgrp filter /etc/postfix/disclaimer chmod 750 /etc/postfix/disclaimer
Next, designate a storage location for your signature files:
mkdir /etc/postfix/disclaimers
7. Create Signatures
For every email address that requires a signature, create a signature file:
echo "signature for mailbox [email protected]" >> /etc/postfix/disclaimers/[email protected] echo "signature for mailbox [email protected]" >> /etc/postfix/disclaimers/[email protected] chgrp -R filter /etc/postfix/disclaimers chmod -R 750 /etc/postfix/disclaimers
8. Update Postfix Configuration
Lastly, adapt your Postfix config to recognize and use the new signature setup.
nano /etc/postfix/master.cf
You should add -o content_filter=dfilt:
after the line with smtp
, like this:
smtp inet n - y - - smtpd
-o content_filter=dfilt:
Spaces int the beginning of the line are important.
Also add the following to the end of the file:
dfilt unix - n n - - pipe
flags=Rq user=filter argv=/etc/postfix/disclaimer -f ${sender} -- ${recipient}
Remember to restart Postfix after making changes:
/etc/init.d/postfix restart
Conclusion
By following these steps, any messages sent from addresses listed in disclaimers will now include the desired signature. This technique greatly enhances email professionalism and brand consistency.
Note:
When sending plain text emails, ensure you're aware of potential encoding issues with signatures. Default encoding is UTF-8, but adjustments might be necessary based on your email client.
iconv -f UTF-8 -t cp1251 test\@fl-mon.com > tmp mv tmp test\@fl-mon.com
Share the article with your friends in social networks, maybe it will be useful to them.
If the article helped you, you can >>thank the author<<