Настройка postfix linux mint

How to Install Postfix Mail Server on Ubuntu 20.04

Postfix is both a popular and preferred Mail Transfer Agent (MTA) for more than 25% of active and public internet mail servers. This attribute has something to do with its open-source status. Many Linux systems benefit from its extensive mail routing and delivery services.

If you are a user of the Ubuntu 20.04 or Ubuntu 18.04 system and wish to install and explore the depths of Postfix MTA, then this article will answer all your queries.

We are going to take you through Ubuntu 20.04 Postfix installation and configuration. The final bit of this tutorial will test Postfix’s mail routing capabilities after we install “s-nail” – it is a popular email client or in more technical terms, a Mail User Agent (MUA).

Requirements

The installation and configuration of Postfix Mail Server on Ubuntu 20.04 requires that you first meet the following requirements.

  • A hosted server with Ubuntu 20.04 as its primary operating system. It is where we will install and configure Postfix Mail Server. On this server, be a sudo-privileged non-root user. The system’s firewall should adhere to UFW configurations.
  • A Fully Qualified Domain Name. It should point to your hosted Ubuntu 20.04 server. If you will be accessing mail externally, your DNS configurations under the MX records should also point to this mail server.

This article assumes that your hosted Ubuntu 20.04 server has something like “mail.example.com” Fully Qualified Domain Name (FQDN) entry under its DNS configurations MX records. You can edit this entry to the preferred domain name you are using. E.g mail.random-tutorials.xyz.

Installing Postfix on Ubuntu

Since Ubuntu’s default repositories already have Postfix, this first installation step should be a walk in the park through the apt package manager. But first, we need to update the Ubuntu 20.04 system’s local package cache.

The command for installing the Postfix package requires a very important parameter called “DEBIAN_PRIORITY”. We will assign it the value “low”. The use of this environment variable will prompt the manual configuration of other additional options by the system user during the Postfix installation process.

$ sudo DEBIAN_PRIORITY=low apt install postfix

Install Postfix in Ubuntu

Once the above command executes, you will be met with a Postfix package configuration prompt that explains the applicability of several useful configurations. Use your keyboard arrow keys to navigate to the “” portion of the prompt. Once it is highlighted in red, press enter.

Postfix Configuration Type

Several menu options will then follow. For each of these menu options, we need to pick one configuration for our Postfix installation. We are going to go with the “Internet Site” Postfix mail configuration. This configuration choice is an ideal match for the Ubuntu 20.04 server infrastructural needs.

Читайте также:  Есть ли 64 битный линукс

Postfix Internet Site

System Mail Name: Do not go with a format entry like mail.example.com. The prompt is asking for a base domain e.g example.com that Postfix will link to Ubuntu 20.04 system users, for example, [email protected] and many others.

Postfix Mail Domain Name

Root and postmaster mail recipient: It should be your Ubuntu 20.04 system or account username e.g ravi.

Postfix Mail Recipient Name

Other destinations to accept mail for?: All domains intended to communicate with Postfix should be listed here. e.g:

$myhostname, random-tutorials.xyz, mail.random-tutorials.xyz, localhost, localhost.random-tutorials.xyz

Postfix Mail Domain

Force synchronous updates on the mail queue?: There is a high chance you are under a journaled filesystem. To be safe, stick to No.

Postfix Force Synchronous Updates

The next prompt regards network blocks configuration. Hit enter on your keyboard.

Postfix Network Block Configuration

Local networks: Stick to the provided defaults and only modify if you understand network range restrictions.

Postfix Local Networks

Mailbox size limit: Let’s you manage the size of your message. Inputting 0 removes message size restrictions.

Postfix Mailbox Size Limit

Local address extension character: Use the provided default character. The character is useful in creating dynamic aliases.

Postfix Local Address Extension Character

Internet protocols to use: Considers the restriction management of Postfix-supported IP versions. Choose the ‘all’ option.

Postfix Internet Protocols

Your installation should then comfortably progress to completion.

Postfix Installation Progress Postfix Installation Completes

Making these changes alongside the installation of Postfix does not make them permanent. You can always edit them by running the following command:

$ sudo dpkg-reconfigure postfix

It will re-launch all the above steps for you to edit where necessary. You will receive a pre-populated prompt from which you will have the chance to change your previous configuration options. It is a nice way of proofreading your Postfix configurations.

Useful Postfix Post-Configuration Changes

The file “/etc/postfix/main.cf” defines most configuration settings associated with Postfix. The command “postconf” will prove useful in editing it. The first edit is changing the variable “home_mailbox” to “maildir/” through the following command.

$ sudo postconf -e 'home_mailbox= Maildir/'

The table “virtual_alias_maps” associates Linux system accounts with arbitrary email accounts. A hash database file (/etc/postfix/virtual) should be its set location.

$ sudo postconf -e 'virtual_alias_maps= hash:/etc/postfix/virtual'

To practically map Linux system user accounts with email accounts, we need to create this virtual maps file. Use a text editor of your choice. In our case, we chose the nano editor.

$ sudo nano /etc/postfix/virtual

This file lists domain addresses that will be accepting email and the system user associated with each delivered mail. Populate the “/etc/postfix/virtual” file with the following format example:

suppo[email protected] ravi [email protected] ravi

There should be a white space between the domain address and the system user. With nano editor, save the file with Ctrl + O keyboard keys combo then hit the Enter key and exit the editor with Ctrl + X .

Читайте также:  Linux остановить скрипт python

Execute the following command to apply the mappings.

$ sudo postmap /etc/postfix/virtual

For all these changes to be effective, restart Postfix with this command:

$ sudo systemctl restart postfix

The UFW firewall configuration should then follow to unblock the needed external connections to server services. To make Postfix an exception on this firewall, the following command will add a firewall rule to UFW.

At this point, you have successfully configured Postfix to work with external connections. To test it, we need a mail client.

Postfix Mail Client Installation and Maildir Structure Initialization

We need to install the “s-nail” package due to its compatibility with the Maildir format. Before this installation, the system’s “MAIL” environment variable should be correctly set. This objective is achieved through several steps.

First, we export this variable to some files:

$ echo 'export MAIL=~/Maildir' | sudo tee -a /etc/bash.bashrc | sudo tee -a /etc/profile.d/mail.sh

Postfix Mail Environment Variable

Now, the current user session needs to read this variable. Source it with the following command.

Finally, use the apt package manager to install our targeted email client (s-nail):

Adjust some settings on the “/etc/s-nail.rc” file before running this email client. We will open this file with the nano editor.

Populate the bottom of this file with the following information and then save the changes to the file.

set emptystart set folder=Maildir set record=+sent

Configure -s-nail Mail Client

The Ubuntu 20.04 system’s Maildir structure is now ready for initialization.

The s-nail command can quickly achieve the Maildir structure creation objective by emailing yourself.

$ echo 'hello LinuxMint Postfix user' | s-nail -s 'hello LinuxMint Postfix user' -Snorecord ubuntu

So far, nothing should happen. On the other hand, an output similar to the following message is normal during the first emailing attempt.

Can't canonicalize "/home/ubuntu/Maildir"

Check for the Maildir directory existence.

The command output should showcase the created directory structure and that a new message exists.

Checking Postfix Maildir Existence

With this directory structure existing, the s-nail client can be put to the test. It will help us see the “hello LinuxMint Postfix user” message we sent earlier.

Clear your Ubuntu 20.04 server terminal with the command:

It should lead to the following instance informing you that you have a new mail.

You have new mail in /home/ubuntu/Maildir

Testing s-nail Client in Ubuntu

Open s-nail client with this command:

An output similar to the following will follow:

s-nail Terminal Output

Press Enter on your keyboard for a final output like the following.

s-nail Mail Message Output

The “hello LinuxMint Postfix user” message we sent is evident from the above output. Type “exit” to leave this s-nail mailbox interface.

Conclusion

Mail server setup and configuration is not only time-consuming but also complex. However, the rewards for being patient through this process have some practical benefits not available in paid mail services. You will be your own mail server administrator with an unmatched understanding of each component that keeps a mail server ticking.

Читайте также:  Fifo pipes in linux

This article tutorial only provides basic email functionality knowledge through Postfix. The foundational components acquired here should help you rise to a full-featured email server user under the Ubuntu 20.04 operating system environment.

Источник

Настройка почтового сервера Postfix

Я кратко расскажу как настроить почтовый сервер (Postfix) для небольшой локальной сети. Почтовый сервер будет работать по протоколу SMTP и будет принимать и отправлять почтовые сообщения, раскладывать принятые сообщения по ящикам юзеров который будет работать по протоколу POP3, для чего необходимо будет поставить сервер popd. Шифрования я юзать не буду.

Для того чтобы входить в сервис Postfix нужно авторизироваться, по этому поставим cyrus-sasl2, ставить буду из портов:

# cd /usr/ports/security/cyrus-sasl2 # make && make install # cd /usr/ports/security/cyrus-sasl2-saslauthd # make && make install

Посмотрим файлик smtpd.conf который лежит в /usr/local/lib/sasl2, он должен содержать:

pwcheck_method: auxprop mech_list: login plain

pwcheck_method: auxprop — показывает нам , что будет используется метод чтения паролей из БД виртуальных юзеров в /etc/sasldb2.

mech_list: login plain — в этой строке показывается что будет использоваться механизм авторизации пользователя для mail-клиента — login и plane: ‘это использует Outlook, Mozilla и The Bat.
Для того чтобы создать нового пользователя (аккаунты) которая будет авторизироваться по SMTP и который будет сохранять в БД можно сделать это следующим образом:
# saslpasswd2 -c -u domain.ru -a smtpauth user
Domain.ru — Доменное имя.
User — Вводите имя юзера.

Можно посмотреть всех sasl пользователей выполнив:

Удалить юзера можно командой:

# saslpasswd2 -d -u domin.ru captain

Установим сервер Postfix:

# cd /usr/ports/mail/postfix # make && make install

Настройка почтового сервера Postfix:

В файле main.cf который лежит /usr/local/etc/postfix/ поправим:

# ee /usr/local/etc/postfix/main.cf

myhostname = mail.domain.ru
mydestination = …, $config_directory/mydestination
mynetworks = $config_directory/mynetworks
(заместо mail.domain.ru пишем свой домен)
В /usr/local/etc/postfix/mydestination ставим ваши домены, если Вы используете несколько, то можно сделать следующее:
domain.ru
domain2.ru
domain3.ru

В /usr/local/etc/postfix/mynetworks Нужно прописать список сетей, из которых можно будет отправлять почту:
127.0.0.1/32
192.168.244.0/24
192.168.77.0/24

Можно в /usr/local/etc/postfix/aliases прописать alias (например captain: cap) и не забыть дать команду:

# postalias /usr/local/etc/postfix/aliases

Создадим скрипт для запуска постфикс /usr/local/etc/rc.d/postfix.sh:

#!/bin/sh [ -x /usr/local/sbin/postfix ] && /usr/local/sbin/postfix start && echo -n ' postfix'

Выставим права, чтобы никто др не смог ничего поменять:

# chmod 500 /usr/local/etc/rc.d/postfix.sh

Для того чтобы использовать авторизацию необходимо в файле /usr/local/etc/postfix/main.cf добавить:
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options =
smtpd_sasl_local_domain =
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions =
permit_sasl_authenticated,
permit_mynetworks,
reject_unauth_destination,
reject_rbl_client list.dsbl.org,
reject_rbl_client relays.ordb.org,
reject_rbl_client dynablock.wirehub.net,
reject_rbl_client blackholes.wirehub.net,
reject_rbl_client dnsbl.njabl.org

5 строк( те что снизу) позволят уменьшить спам (используем черный списков).

# /usr/local/etc/rc.d/saslauthd.sh start # /usr/local/etc/rc.d/postfix.sh start

Почта пользователей которая будет поступать по локалке будет сохранятся в их почтовых ящиках, которые в данном примере будут текстовыми файлами с именами пользователей в /usr/var/mail/. Клиент почты забирает почту по POP3, подключившись к серверу popd по 110-му порту. Поставим сервер popd:

# cd /usr/ports/mail/popd # make && make install

Запустить его можно демоном:

А можно через сервер inetd (xinetd). Я юзаю xinetd. Настройка почтового сервера Postfix завершена!

Источник

Оцените статью
Adblock
detector