Redirecting mail for the root user

Open the aliases in the text editor:

sudo nano /etc/aliases

Example of redirecting the root mail to admin@example.net:

root: admin@example.net

You can forward directly to several addresses:

root: admin@example.net,user@example.net

Press Ctrl+O then Enter and Ctrl+X to exit the nano editor.

For the changes to take effect, you must update the alias database with the command:

cd /etc
sudo newaliases

If postfix is used as the mail sending server, then the /etc/postfix/main.cf config file can specify other paths to the list and the alias base, for example:

alias_maps = hash:/etc/postfix/aliases
alias_database = hash:/etc/postfix/aliases

In this case, edit this file too:

sudo nano /etc/postfix/aliases
cd /etc/postfix/aliases
sudo newaliases
sudo service postfix restart

For verification, you can send an email to the user as root:

echo 'Test' | mail -s Test root

Monitoring Postfix in Zabbix

First, configure the Zabbix agent.

Create a file (in the nano editor, press Ctrl+X to exit, and y/n to save or discard changes):

nano /etc/zabbix/zabbix_agentd.d/userparameter_postfix.conf

Add to it:

UserParameter=postfix.maildrop, find /var/spool/postfix/maildrop -type f | wc -l
UserParameter=postfix.deferred, find /var/spool/postfix/deferred -type f | wc -l
UserParameter=postfix.incoming, find /var/spool/postfix/incoming -type f | wc -l
UserParameter=postfix.active, find /var/spool/postfix/active -type f | wc -l
UserParameter=postfix.queue, mailq | grep -v "Mail queue is empty" | grep -c '^[0-9A-Z]'

Alternatively, you can simply add the lines above to the Zabbix agent configuration file.

Also open the Zabbix agent configuration file:

nano /etc/zabbix/zabbix_agentd.conf

We will allow Zabbix agent to work as root with the user specifying:

AllowRoot=1

Restart the Zabbix agent to apply the changes:

sudo /etc/init.d/zabbix-agent restart

Now go to the Zabbix server.
Create a Postfix template, add data items to it, specifying the type – Zabbix agent, and the keys: postfix.maildrop, postfix.deferred, postfix.incoming, postfix.active, postfix.queue.
Create graphics for the created data items.

You can also create a data item that counts the number of Postfix processes by specifying the type – Zabbix agent, and the key:

proc.num[,postfix]

Also create a trigger that tells when processes 0.

Download the ready template here – Zabbix шаблон для Postfix

Installing and Configuring Postfix

Postfix — mail transfer agent (MTA) with open source.

Assume that the IP address of the server is configured with a domain name, from which the mail will be sent in the future.

Switch directly to the root user:

sudo -i

Proceed to install Postfix.
To install in Ubuntu, perform:

apt-get update
apt-get install postfix

For installation in CentOS:

yum install postfix

During the installation, some questions will be asked.
1) Choose the “Internet site”
2) Specify the fully qualified domain name server (FQDN), for example example.com

After that Postfix will start working.
Configuration files are usually found in /etc/postfix.

We can look at the status/restart/stop/start Postfix commands:

service postfix status
service postfix restart
service postfix stop
service postfix start

If necessary, you can reconfigure by typing the following command:

dpkg-reconfigure postfix

Let’s see if the ports are used:

netstat -na | grep LISTEN | grep 25
netstat -na | grep LISTEN | grep 587

You can perform an automatic check:

postfix check

Let’s try to send the letter to the specified address (after the command we will type the desired text and put a point for completion):

sendmail -v admin@example.com

You can search the logs for the information you need via grep, for example, find all the lines that contain admin@example.com:

grep admin@example.com /var/log/mail.log

You can also connect from another host to the postfix port via telnet and make sure that it is running.

For diagnostics, you can observe the connections using tcpdump:

tcpdump port 25
tcpdump port 587

If there are more than one IP on the server, and the domain is only on one, we will specify from which IP the sending will be done:

sudo nano /etc/postfix/main.cf
smtp_bind_address = 11.1.1.2

You can also specify on which interfaces Postfix will work:

#inet_interfaces = all
inet_interfaces = 127.0.0.1

Restart Postfix to apply the changes:

sudo /etc/init.d/postfix restart

How to enable SMTP without SSL on port 25 in iRedMail / Postfix

To allow the sending of messages on the mail server without encryption via port 25, you need to open the Postfix configuration file, for example, in the nano editor (in which Ctrl+X to exit, y/n to save or cancel changes):

sudo nano /etc/postfix/main.cf

And uncomment two lines:

smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous

And leave the commented line:

#smtpd_tls_auth_only=yes

Reload Postfix to apply the changes:

sudo service postfix restart

After that it will be possible to send messages via SMTP through port 25 without SSL, and as usual through 587 with SSL.

See also:
Allow insecure connections to POP3 / IMAP iRedMail

How to fix error “host NAME greeted me with my own hostname NAME”

I noticed once on one server that Postfix does not always send mail, the logs had the following error:

warning: host NAME[192.168.5.5]:25 greeted me with my own hostname NAME

After seeing the host name:

hostname -f

Found that it is not correct and coincides with that on which the mail is sent!

Changed the host name to the correct one in the following files (in the nano editor Ctrl+X to exit, y/n to save or cancel changes):

sudo nano /etc/hostname
sudo nano /etc/postfix/main.cf
sudo nano /etc/hosts

Done, after that the error did not appear and the mail was successfully delivered.