Skip to content
www.mytechnote.ru
Menu
  • Administration
    • Scripts
  • Equipment
    • Reviews
    • Instructions
  • Other
  • English
    • English
    • Русский
Menu

How to Set Up Email Signatures with Postfix on Ubuntu Server 16.04

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

Using an editor like 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 test@mytechnote.ru" >> /etc/postfix/disclaimers/test@mytechnote.ru
echo "signature for mailbox test1@mytechnote.ru" >> /etc/postfix/disclaimers/test1@mytechnote.ru
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

Posted on 16.11.201730.05.2024 by sanglyb

Post navigation

← How to Efficiently Rename Your Linux Terminal Windows: A Simple Guide for Ubuntu & CentOS Users
Optimize Web Development Workflow with Sublime and LiveReload on Ubuntu →

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Подписывайтесь

Youtube
vk
telegram
github
twitter
rss
  • Форум
  • Об авторе
  • Поддержать автора

Популярные записи

Новые записи

  • How to Extend an LVM Partition in Linux
  • SCCM Reporting Errors After Migrating from SQL Server 2016 to 2019
  • Problem Using PassFiltEx on Older CPUs
  • How to remove attachments from old calendar events in Exchange using a script
  • How to download and install Office 2024 LTSC

Архивы

  • 2026 (3)
  • 2025 (5)
  • 2024 (7)
  • 2023 (30)
  • 2022 (4)
  • 2020 (17)
  • 2017 (82)
  • 2016 (5)
© 2015-2026 www.mytechnote.ru
Использование материалов сайта возможно только с разрешения владельца или обязательна индексируемая, прямая, передающая вес ссылка на материал.