<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://10.99.0.100:8087/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Administrator</id>
	<title>Fvettore-WIKI - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="http://10.99.0.100:8087/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Administrator"/>
	<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/wiki/Special:Contributions/Administrator"/>
	<updated>2026-04-16T13:43:44Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.44.0</generator>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=242</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=242"/>
		<updated>2025-10-16T15:03:52Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* SPF filtering (strongly suggested) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Quick and dirty (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===Prerequisites===&lt;br /&gt;
configure your DNS properly&lt;br /&gt;
*A record matching the FQDN of this server&lt;br /&gt;
*MX record for the domains to the IP of this server&lt;br /&gt;
*ensure reverse IP is configured properly or some external servers can refuse your email&lt;br /&gt;
*not mandatory: SPF record for your domains matching with the IP of your server&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQDN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
====USERS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
There are more fields than in usual tutorials you can retrieve online. &lt;br /&gt;
*enabled: user can receive emails&lt;br /&gt;
*imap_enabled: user can retieve email with IMAPs protocol&lt;br /&gt;
*smtp_enabled: user can use smtp service to send email from a remote client&lt;br /&gt;
*smtp_username: to authenticate SMTP, can be different from the email address&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
====DOMAINS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
====ALIASES====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, smtp_username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 dovecot_destination_recipient_limit = 1&lt;br /&gt;
 &lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtpd_tls_security_level = may&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/server08.vettore.org&lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/chain.pem&lt;br /&gt;
 &lt;br /&gt;
 smtpd_client_restrictions = permit_mynetworks,&lt;br /&gt;
        permit_sasl_authenticated,&lt;br /&gt;
        reject_unauth_destination,&lt;br /&gt;
        reject_unknown_sender_domain,&lt;br /&gt;
        reject_unknown_reverse_client_hostname,&lt;br /&gt;
        reject_rbl_client b.barracudacentral.org,&lt;br /&gt;
        reject_rbl_client blackholes.easynet.nl,&lt;br /&gt;
        reject_rbl_client proxies.blackholes.wirehub.net,&lt;br /&gt;
        reject_rbl_client bl.spamcop.net,&lt;br /&gt;
  &lt;br /&gt;
 #disabled for several reasons (be careful to enable again)&lt;br /&gt;
 &lt;br /&gt;
 #       reject_rbl_client sbl.spamhaus.org,&lt;br /&gt;
 #        reject_rbl_client zen.spamhaus.org,&lt;br /&gt;
 #        reject_rhsbl_sender blackhole.securitysage.com,&lt;br /&gt;
 #        reject_rbl_client cbl.abuseat.org,&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above (virtual_xxx)&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Edit  /etc/dovecot/conf.d/10-auth.conf:&amp;lt;br&amp;gt;&lt;br /&gt;
Enable loading of the above file removing comment from &lt;br /&gt;
 !include auth-sql.conf.ext&lt;br /&gt;
and comment out in order to disable PAM (otherwise you will get errors in /var/log/secure)&lt;br /&gt;
 #!include auth-system.conf.ext&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the /etc/dovecot/conf.d/auth-sql.conf.ext file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND imap_enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above &lt;br /&gt;
 ssl_cert = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 ssl_key = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 #leave the following commented for normal configuration&lt;br /&gt;
 #ssl_ca = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/chain.pem&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below). LMTP is optional (see SIEVE paragraph later)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can configure different users for SMTP and IMAP or enable/disable SMTP for IMAP users.&lt;br /&gt;
The table structure created above have fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting smtp_enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND smtp_enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Verify SSL connections===&lt;br /&gt;
====SMTP starttls====&lt;br /&gt;
 openssl s_client -starttls smtp -servername server08.vettore.org -connect server08.vettore.org:587&lt;br /&gt;
====IMAP startls==== &lt;br /&gt;
 openssl s_client -starttls imap -servername server08.vettore.org -connect server08.vettore.org:143&lt;br /&gt;
&lt;br /&gt;
==Sieve/pigeonhole (optional)==&lt;br /&gt;
 dnf install dovecot-pigeonhole&lt;br /&gt;
&lt;br /&gt;
edit ./conf.d/20-lmtp.conf &amp;amp; uncomment&lt;br /&gt;
 mail_plugins = $mail_plugins sievement&lt;br /&gt;
&lt;br /&gt;
edit ./conf.d/20-managesieve.conf and uncomment &lt;br /&gt;
 protocols = $protocols sieve&lt;br /&gt;
&lt;br /&gt;
and&lt;br /&gt;
 service managesieve-login {&lt;br /&gt;
  inet_listener sieve {&lt;br /&gt;
    port = 4190&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
restart dovecot&amp;lt;/br&amp;gt;&lt;br /&gt;
Try to telnet your local port 4190 to check if managesieve service is running&amp;lt;/br&amp;gt;&lt;br /&gt;
Enable LMTP in ./conf/10-master.conf&lt;br /&gt;
&lt;br /&gt;
 service lmtp {&lt;br /&gt;
 unix_listener /var/spool/postfix/private/dovecot-lmtp {&lt;br /&gt;
    group = postfix&lt;br /&gt;
    mode = 0600&lt;br /&gt;
    user = postfix&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
in /etc/postfix/main.cf edit the virtual_transport&lt;br /&gt;
 virtual_transport = lmtp:unix:/var/spool/postfix/private/dovecot-lmtp&lt;br /&gt;
&lt;br /&gt;
restart both postfix and dovecot&lt;br /&gt;
== SPF filtering (strongly suggested)==&lt;br /&gt;
 dnf install pypolicyd-spf&lt;br /&gt;
create user&lt;br /&gt;
 adduser policyd-spf --user-group --no-create-home -s /bin/false&lt;br /&gt;
Add to /etc/postfix/master.cf&lt;br /&gt;
 policyd-spf  unix  -       n       n       -       0       spawn&lt;br /&gt;
    user=policyd-spf argv=/usr/libexec/postfix/policyd-spf&lt;br /&gt;
Add to /etc/postfix/main.cf unde smtp_client_restrictions&lt;br /&gt;
 smtpd_client_restrictions = permit_mynetworks,&lt;br /&gt;
        permit_sasl_authenticated,&lt;br /&gt;
        reject_unauth_destination,&lt;br /&gt;
        reject_unknown_sender_domain,&lt;br /&gt;
        reject_unknown_reverse_client_hostname,&lt;br /&gt;
        ........&lt;br /&gt;
        check_policy_service unix:private/policyd-spf,&lt;br /&gt;
&lt;br /&gt;
Restart postfix&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=241</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=241"/>
		<updated>2025-10-16T15:03:21Z</updated>

		<summary type="html">&lt;p&gt;Administrator: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Quick and dirty (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===Prerequisites===&lt;br /&gt;
configure your DNS properly&lt;br /&gt;
*A record matching the FQDN of this server&lt;br /&gt;
*MX record for the domains to the IP of this server&lt;br /&gt;
*ensure reverse IP is configured properly or some external servers can refuse your email&lt;br /&gt;
*not mandatory: SPF record for your domains matching with the IP of your server&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQDN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
====USERS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
There are more fields than in usual tutorials you can retrieve online. &lt;br /&gt;
*enabled: user can receive emails&lt;br /&gt;
*imap_enabled: user can retieve email with IMAPs protocol&lt;br /&gt;
*smtp_enabled: user can use smtp service to send email from a remote client&lt;br /&gt;
*smtp_username: to authenticate SMTP, can be different from the email address&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
====DOMAINS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
====ALIASES====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, smtp_username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 dovecot_destination_recipient_limit = 1&lt;br /&gt;
 &lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtpd_tls_security_level = may&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/server08.vettore.org&lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/chain.pem&lt;br /&gt;
 &lt;br /&gt;
 smtpd_client_restrictions = permit_mynetworks,&lt;br /&gt;
        permit_sasl_authenticated,&lt;br /&gt;
        reject_unauth_destination,&lt;br /&gt;
        reject_unknown_sender_domain,&lt;br /&gt;
        reject_unknown_reverse_client_hostname,&lt;br /&gt;
        reject_rbl_client b.barracudacentral.org,&lt;br /&gt;
        reject_rbl_client blackholes.easynet.nl,&lt;br /&gt;
        reject_rbl_client proxies.blackholes.wirehub.net,&lt;br /&gt;
        reject_rbl_client bl.spamcop.net,&lt;br /&gt;
  &lt;br /&gt;
 #disabled for several reasons (be careful to enable again)&lt;br /&gt;
 &lt;br /&gt;
 #       reject_rbl_client sbl.spamhaus.org,&lt;br /&gt;
 #        reject_rbl_client zen.spamhaus.org,&lt;br /&gt;
 #        reject_rhsbl_sender blackhole.securitysage.com,&lt;br /&gt;
 #        reject_rbl_client cbl.abuseat.org,&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above (virtual_xxx)&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Edit  /etc/dovecot/conf.d/10-auth.conf:&amp;lt;br&amp;gt;&lt;br /&gt;
Enable loading of the above file removing comment from &lt;br /&gt;
 !include auth-sql.conf.ext&lt;br /&gt;
and comment out in order to disable PAM (otherwise you will get errors in /var/log/secure)&lt;br /&gt;
 #!include auth-system.conf.ext&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the /etc/dovecot/conf.d/auth-sql.conf.ext file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND imap_enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above &lt;br /&gt;
 ssl_cert = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 ssl_key = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 #leave the following commented for normal configuration&lt;br /&gt;
 #ssl_ca = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/chain.pem&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below). LMTP is optional (see SIEVE paragraph later)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can configure different users for SMTP and IMAP or enable/disable SMTP for IMAP users.&lt;br /&gt;
The table structure created above have fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting smtp_enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND smtp_enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Verify SSL connections===&lt;br /&gt;
====SMTP starttls====&lt;br /&gt;
 openssl s_client -starttls smtp -servername server08.vettore.org -connect server08.vettore.org:587&lt;br /&gt;
====IMAP startls==== &lt;br /&gt;
 openssl s_client -starttls imap -servername server08.vettore.org -connect server08.vettore.org:143&lt;br /&gt;
&lt;br /&gt;
==Sieve/pigeonhole (optional)==&lt;br /&gt;
 dnf install dovecot-pigeonhole&lt;br /&gt;
&lt;br /&gt;
edit ./conf.d/20-lmtp.conf &amp;amp; uncomment&lt;br /&gt;
 mail_plugins = $mail_plugins sievement&lt;br /&gt;
&lt;br /&gt;
edit ./conf.d/20-managesieve.conf and uncomment &lt;br /&gt;
 protocols = $protocols sieve&lt;br /&gt;
&lt;br /&gt;
and&lt;br /&gt;
 service managesieve-login {&lt;br /&gt;
  inet_listener sieve {&lt;br /&gt;
    port = 4190&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
restart dovecot&amp;lt;/br&amp;gt;&lt;br /&gt;
Try to telnet your local port 4190 to check if managesieve service is running&amp;lt;/br&amp;gt;&lt;br /&gt;
Enable LMTP in ./conf/10-master.conf&lt;br /&gt;
&lt;br /&gt;
 service lmtp {&lt;br /&gt;
 unix_listener /var/spool/postfix/private/dovecot-lmtp {&lt;br /&gt;
    group = postfix&lt;br /&gt;
    mode = 0600&lt;br /&gt;
    user = postfix&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
in /etc/postfix/main.cf edit the virtual_transport&lt;br /&gt;
 virtual_transport = lmtp:unix:/var/spool/postfix/private/dovecot-lmtp&lt;br /&gt;
&lt;br /&gt;
restart both postfix and dovecot&lt;br /&gt;
== SPF filtering (strongly suggested)==&lt;br /&gt;
 dnf install pypolicyd-spf&lt;br /&gt;
create user&lt;br /&gt;
 adduser policyd-spf --user-group --no-create-home -s /bin/false&lt;br /&gt;
Add to /etc/postfix/master.cf&lt;br /&gt;
 policyd-spf  unix  -       n       n       -       0       spawn&lt;br /&gt;
    user=policyd-spf argv=/usr/libexec/postfix/policyd-spf&lt;br /&gt;
Add to /etc/postfix/main.cf unde smtp_client_restrictions&lt;br /&gt;
 smtpd_client_restrictions = permit_mynetworks,&lt;br /&gt;
        permit_sasl_authenticated,&lt;br /&gt;
        reject_unauth_destination,&lt;br /&gt;
        reject_unknown_sender_domain,&lt;br /&gt;
        reject_unknown_reverse_client_hostname,&lt;br /&gt;
        ........&lt;br /&gt;
        check_policy_service unix:private/policyd-spf,&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=240</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=240"/>
		<updated>2025-10-16T10:57:07Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Dovecot IMAP */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Quick and dirty (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===Prerequisites===&lt;br /&gt;
configure your DNS properly&lt;br /&gt;
*A record matching the FQDN of this server&lt;br /&gt;
*MX record for the domains to the IP of this server&lt;br /&gt;
*ensure reverse IP is configured properly or some external servers can refuse your email&lt;br /&gt;
*not mandatory: SPF record for your domains matching with the IP of your server&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQDN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
====USERS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
There are more fields than in usual tutorials you can retrieve online. &lt;br /&gt;
*enabled: user can receive emails&lt;br /&gt;
*imap_enabled: user can retieve email with IMAPs protocol&lt;br /&gt;
*smtp_enabled: user can use smtp service to send email from a remote client&lt;br /&gt;
*smtp_username: to authenticate SMTP, can be different from the email address&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
====DOMAINS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
====ALIASES====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, smtp_username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 dovecot_destination_recipient_limit = 1&lt;br /&gt;
 &lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtpd_tls_security_level = may&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/server08.vettore.org&lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/chain.pem&lt;br /&gt;
 &lt;br /&gt;
 smtpd_client_restrictions = permit_mynetworks,&lt;br /&gt;
        permit_sasl_authenticated,&lt;br /&gt;
        reject_unauth_destination,&lt;br /&gt;
        reject_unknown_sender_domain,&lt;br /&gt;
        reject_unknown_reverse_client_hostname,&lt;br /&gt;
        reject_rbl_client b.barracudacentral.org,&lt;br /&gt;
        reject_rbl_client blackholes.easynet.nl,&lt;br /&gt;
        reject_rbl_client proxies.blackholes.wirehub.net,&lt;br /&gt;
        reject_rbl_client bl.spamcop.net,&lt;br /&gt;
  &lt;br /&gt;
 #disabled for several reasons (be careful to enable again)&lt;br /&gt;
 &lt;br /&gt;
 #       reject_rbl_client sbl.spamhaus.org,&lt;br /&gt;
 #        reject_rbl_client zen.spamhaus.org,&lt;br /&gt;
 #        reject_rhsbl_sender blackhole.securitysage.com,&lt;br /&gt;
 #        reject_rbl_client cbl.abuseat.org,&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above (virtual_xxx)&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Edit  /etc/dovecot/conf.d/10-auth.conf:&amp;lt;br&amp;gt;&lt;br /&gt;
Enable loading of the above file removing comment from &lt;br /&gt;
 !include auth-sql.conf.ext&lt;br /&gt;
and comment out in order to disable PAM (otherwise you will get errors in /var/log/secure)&lt;br /&gt;
 #!include auth-system.conf.ext&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the /etc/dovecot/conf.d/auth-sql.conf.ext file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND imap_enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above &lt;br /&gt;
 ssl_cert = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 ssl_key = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 #leave the following commented for normal configuration&lt;br /&gt;
 #ssl_ca = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/chain.pem&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below). LMTP is optional (see SIEVE paragraph later)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can configure different users for SMTP and IMAP or enable/disable SMTP for IMAP users.&lt;br /&gt;
The table structure created above have fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting smtp_enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND smtp_enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Verify SSL connections===&lt;br /&gt;
====SMTP starttls====&lt;br /&gt;
 openssl s_client -starttls smtp -servername server08.vettore.org -connect server08.vettore.org:587&lt;br /&gt;
====IMAP startls==== &lt;br /&gt;
 openssl s_client -starttls imap -servername server08.vettore.org -connect server08.vettore.org:143&lt;br /&gt;
&lt;br /&gt;
==Sieve/pigeonhole (optional)==&lt;br /&gt;
 dnf install dovecot-pigeonhole&lt;br /&gt;
&lt;br /&gt;
edit ./conf.d/20-lmtp.conf &amp;amp; uncomment&lt;br /&gt;
 mail_plugins = $mail_plugins sievement&lt;br /&gt;
&lt;br /&gt;
edit ./conf.d/20-managesieve.conf and uncomment &lt;br /&gt;
 protocols = $protocols sieve&lt;br /&gt;
&lt;br /&gt;
and&lt;br /&gt;
 service managesieve-login {&lt;br /&gt;
  inet_listener sieve {&lt;br /&gt;
    port = 4190&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
restart dovecot&amp;lt;/br&amp;gt;&lt;br /&gt;
Try to telnet your local port 4190 to check if managesieve service is running&amp;lt;/br&amp;gt;&lt;br /&gt;
Enable LMTP in ./conf/10-master.conf&lt;br /&gt;
&lt;br /&gt;
 service lmtp {&lt;br /&gt;
 unix_listener /var/spool/postfix/private/dovecot-lmtp {&lt;br /&gt;
    group = postfix&lt;br /&gt;
    mode = 0600&lt;br /&gt;
    user = postfix&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
in /etc/postfix/main.cf edit the virtual_transport&lt;br /&gt;
 virtual_transport = lmtp:unix:/var/spool/postfix/private/dovecot-lmtp&lt;br /&gt;
&lt;br /&gt;
restart both postfix and dovecot&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=239</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=239"/>
		<updated>2025-10-16T10:55:31Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Sieve/pidgeonhole (optional) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Quick and dirty (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===Prerequisites===&lt;br /&gt;
configure your DNS properly&lt;br /&gt;
*A record matching the FQDN of this server&lt;br /&gt;
*MX record for the domains to the IP of this server&lt;br /&gt;
*ensure reverse IP is configured properly or some external servers can refuse your email&lt;br /&gt;
*not mandatory: SPF record for your domains matching with the IP of your server&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQDN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
====USERS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
There are more fields than in usual tutorials you can retrieve online. &lt;br /&gt;
*enabled: user can receive emails&lt;br /&gt;
*imap_enabled: user can retieve email with IMAPs protocol&lt;br /&gt;
*smtp_enabled: user can use smtp service to send email from a remote client&lt;br /&gt;
*smtp_username: to authenticate SMTP, can be different from the email address&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
====DOMAINS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
====ALIASES====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, smtp_username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 dovecot_destination_recipient_limit = 1&lt;br /&gt;
 &lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtpd_tls_security_level = may&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/server08.vettore.org&lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/chain.pem&lt;br /&gt;
 &lt;br /&gt;
 smtpd_client_restrictions = permit_mynetworks,&lt;br /&gt;
        permit_sasl_authenticated,&lt;br /&gt;
        reject_unauth_destination,&lt;br /&gt;
        reject_unknown_sender_domain,&lt;br /&gt;
        reject_unknown_reverse_client_hostname,&lt;br /&gt;
        reject_rbl_client b.barracudacentral.org,&lt;br /&gt;
        reject_rbl_client blackholes.easynet.nl,&lt;br /&gt;
        reject_rbl_client proxies.blackholes.wirehub.net,&lt;br /&gt;
        reject_rbl_client bl.spamcop.net,&lt;br /&gt;
  &lt;br /&gt;
 #disabled for several reasons (be careful to enable again)&lt;br /&gt;
 &lt;br /&gt;
 #       reject_rbl_client sbl.spamhaus.org,&lt;br /&gt;
 #        reject_rbl_client zen.spamhaus.org,&lt;br /&gt;
 #        reject_rhsbl_sender blackhole.securitysage.com,&lt;br /&gt;
 #        reject_rbl_client cbl.abuseat.org,&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above (virtual_xxx)&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Edit  /etc/dovecot/conf.d/10-auth.conf:&amp;lt;br&amp;gt;&lt;br /&gt;
Enable loading of the above file removing comment from &lt;br /&gt;
 !include auth-sql.conf.ext&lt;br /&gt;
and comment out in order to disable PAM (otherwise you will get errors in /var/log/secure)&lt;br /&gt;
 #!include auth-system.conf.ext&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the /etc/dovecot/conf.d/auth-sql.conf.ext file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND imap_enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above &lt;br /&gt;
 ssl_cert = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 ssl_key = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 #leave the following commented for normal configuration&lt;br /&gt;
 #ssl_ca = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/chain.pem&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can configure different users for SMTP and IMAP or enable/disable SMTP for IMAP users.&lt;br /&gt;
The table structure created above have fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting smtp_enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND smtp_enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Verify SSL connections===&lt;br /&gt;
====SMTP starttls====&lt;br /&gt;
 openssl s_client -starttls smtp -servername server08.vettore.org -connect server08.vettore.org:587&lt;br /&gt;
====IMAP startls==== &lt;br /&gt;
 openssl s_client -starttls imap -servername server08.vettore.org -connect server08.vettore.org:143&lt;br /&gt;
&lt;br /&gt;
==Sieve/pigeonhole (optional)==&lt;br /&gt;
 dnf install dovecot-pigeonhole&lt;br /&gt;
&lt;br /&gt;
edit ./conf.d/20-lmtp.conf &amp;amp; uncomment&lt;br /&gt;
 mail_plugins = $mail_plugins sievement&lt;br /&gt;
&lt;br /&gt;
edit ./conf.d/20-managesieve.conf and uncomment &lt;br /&gt;
 protocols = $protocols sieve&lt;br /&gt;
&lt;br /&gt;
and&lt;br /&gt;
 service managesieve-login {&lt;br /&gt;
  inet_listener sieve {&lt;br /&gt;
    port = 4190&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
restart dovecot&amp;lt;/br&amp;gt;&lt;br /&gt;
Try to telnet your local port 4190 to check if managesieve service is running&amp;lt;/br&amp;gt;&lt;br /&gt;
Enable LMTP in ./conf/10-master.conf&lt;br /&gt;
&lt;br /&gt;
 service lmtp {&lt;br /&gt;
 unix_listener /var/spool/postfix/private/dovecot-lmtp {&lt;br /&gt;
    group = postfix&lt;br /&gt;
    mode = 0600&lt;br /&gt;
    user = postfix&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
in /etc/postfix/main.cf edit the virtual_transport&lt;br /&gt;
 virtual_transport = lmtp:unix:/var/spool/postfix/private/dovecot-lmtp&lt;br /&gt;
&lt;br /&gt;
restart both postfix and dovecot&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=238</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=238"/>
		<updated>2025-10-16T10:54:12Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Sieve/pidgeonhole (optional) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Quick and dirty (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===Prerequisites===&lt;br /&gt;
configure your DNS properly&lt;br /&gt;
*A record matching the FQDN of this server&lt;br /&gt;
*MX record for the domains to the IP of this server&lt;br /&gt;
*ensure reverse IP is configured properly or some external servers can refuse your email&lt;br /&gt;
*not mandatory: SPF record for your domains matching with the IP of your server&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQDN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
====USERS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
There are more fields than in usual tutorials you can retrieve online. &lt;br /&gt;
*enabled: user can receive emails&lt;br /&gt;
*imap_enabled: user can retieve email with IMAPs protocol&lt;br /&gt;
*smtp_enabled: user can use smtp service to send email from a remote client&lt;br /&gt;
*smtp_username: to authenticate SMTP, can be different from the email address&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
====DOMAINS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
====ALIASES====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, smtp_username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 dovecot_destination_recipient_limit = 1&lt;br /&gt;
 &lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtpd_tls_security_level = may&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/server08.vettore.org&lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/chain.pem&lt;br /&gt;
 &lt;br /&gt;
 smtpd_client_restrictions = permit_mynetworks,&lt;br /&gt;
        permit_sasl_authenticated,&lt;br /&gt;
        reject_unauth_destination,&lt;br /&gt;
        reject_unknown_sender_domain,&lt;br /&gt;
        reject_unknown_reverse_client_hostname,&lt;br /&gt;
        reject_rbl_client b.barracudacentral.org,&lt;br /&gt;
        reject_rbl_client blackholes.easynet.nl,&lt;br /&gt;
        reject_rbl_client proxies.blackholes.wirehub.net,&lt;br /&gt;
        reject_rbl_client bl.spamcop.net,&lt;br /&gt;
  &lt;br /&gt;
 #disabled for several reasons (be careful to enable again)&lt;br /&gt;
 &lt;br /&gt;
 #       reject_rbl_client sbl.spamhaus.org,&lt;br /&gt;
 #        reject_rbl_client zen.spamhaus.org,&lt;br /&gt;
 #        reject_rhsbl_sender blackhole.securitysage.com,&lt;br /&gt;
 #        reject_rbl_client cbl.abuseat.org,&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above (virtual_xxx)&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Edit  /etc/dovecot/conf.d/10-auth.conf:&amp;lt;br&amp;gt;&lt;br /&gt;
Enable loading of the above file removing comment from &lt;br /&gt;
 !include auth-sql.conf.ext&lt;br /&gt;
and comment out in order to disable PAM (otherwise you will get errors in /var/log/secure)&lt;br /&gt;
 #!include auth-system.conf.ext&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the /etc/dovecot/conf.d/auth-sql.conf.ext file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND imap_enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above &lt;br /&gt;
 ssl_cert = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 ssl_key = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 #leave the following commented for normal configuration&lt;br /&gt;
 #ssl_ca = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/chain.pem&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can configure different users for SMTP and IMAP or enable/disable SMTP for IMAP users.&lt;br /&gt;
The table structure created above have fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting smtp_enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND smtp_enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Verify SSL connections===&lt;br /&gt;
====SMTP starttls====&lt;br /&gt;
 openssl s_client -starttls smtp -servername server08.vettore.org -connect server08.vettore.org:587&lt;br /&gt;
====IMAP startls==== &lt;br /&gt;
 openssl s_client -starttls imap -servername server08.vettore.org -connect server08.vettore.org:143&lt;br /&gt;
&lt;br /&gt;
==Sieve/pidgeonhole (optional)==&lt;br /&gt;
 dnf install dovecot-pigeonhole&lt;br /&gt;
&lt;br /&gt;
edit ./conf.d/20-lmtp.conf &amp;amp; uncomment&lt;br /&gt;
 mail_plugins = $mail_plugins sievement&lt;br /&gt;
&lt;br /&gt;
edit ./conf.d/20-managesieve.conf and uncomment &lt;br /&gt;
 protocols = $protocols sieve&lt;br /&gt;
&lt;br /&gt;
and&lt;br /&gt;
 service managesieve-login {&lt;br /&gt;
  inet_listener sieve {&lt;br /&gt;
    port = 4190&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
restart dovecot&amp;lt;/br&amp;gt;&lt;br /&gt;
Try to telnet your local port 4190 to check if managesieve service is running&amp;lt;/br&amp;gt;&lt;br /&gt;
Enable LMTP in ./conf/10-master.conf&lt;br /&gt;
&lt;br /&gt;
 service lmtp {&lt;br /&gt;
 unix_listener /var/spool/postfix/private/dovecot-lmtp {&lt;br /&gt;
    group = postfix&lt;br /&gt;
    mode = 0600&lt;br /&gt;
    user = postfix&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
in /etc/postfix/main.cf edit the virtual_transport&lt;br /&gt;
 virtual_transport = lmtp:unix:/var/spool/postfix/private/dovecot-lmtp&lt;br /&gt;
&lt;br /&gt;
restart both postfix and dovecot&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=237</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=237"/>
		<updated>2025-10-16T09:27:43Z</updated>

		<summary type="html">&lt;p&gt;Administrator: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Quick and dirty (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===Prerequisites===&lt;br /&gt;
configure your DNS properly&lt;br /&gt;
*A record matching the FQDN of this server&lt;br /&gt;
*MX record for the domains to the IP of this server&lt;br /&gt;
*ensure reverse IP is configured properly or some external servers can refuse your email&lt;br /&gt;
*not mandatory: SPF record for your domains matching with the IP of your server&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQDN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
====USERS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
There are more fields than in usual tutorials you can retrieve online. &lt;br /&gt;
*enabled: user can receive emails&lt;br /&gt;
*imap_enabled: user can retieve email with IMAPs protocol&lt;br /&gt;
*smtp_enabled: user can use smtp service to send email from a remote client&lt;br /&gt;
*smtp_username: to authenticate SMTP, can be different from the email address&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
====DOMAINS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
====ALIASES====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, smtp_username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 dovecot_destination_recipient_limit = 1&lt;br /&gt;
 &lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtpd_tls_security_level = may&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/server08.vettore.org&lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/chain.pem&lt;br /&gt;
 &lt;br /&gt;
 smtpd_client_restrictions = permit_mynetworks,&lt;br /&gt;
        permit_sasl_authenticated,&lt;br /&gt;
        reject_unauth_destination,&lt;br /&gt;
        reject_unknown_sender_domain,&lt;br /&gt;
        reject_unknown_reverse_client_hostname,&lt;br /&gt;
        reject_rbl_client b.barracudacentral.org,&lt;br /&gt;
        reject_rbl_client blackholes.easynet.nl,&lt;br /&gt;
        reject_rbl_client proxies.blackholes.wirehub.net,&lt;br /&gt;
        reject_rbl_client bl.spamcop.net,&lt;br /&gt;
  &lt;br /&gt;
 #disabled for several reasons (be careful to enable again)&lt;br /&gt;
 &lt;br /&gt;
 #       reject_rbl_client sbl.spamhaus.org,&lt;br /&gt;
 #        reject_rbl_client zen.spamhaus.org,&lt;br /&gt;
 #        reject_rhsbl_sender blackhole.securitysage.com,&lt;br /&gt;
 #        reject_rbl_client cbl.abuseat.org,&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above (virtual_xxx)&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Edit  /etc/dovecot/conf.d/10-auth.conf:&amp;lt;br&amp;gt;&lt;br /&gt;
Enable loading of the above file removing comment from &lt;br /&gt;
 !include auth-sql.conf.ext&lt;br /&gt;
and comment out in order to disable PAM (otherwise you will get errors in /var/log/secure)&lt;br /&gt;
 #!include auth-system.conf.ext&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the /etc/dovecot/conf.d/auth-sql.conf.ext file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND imap_enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above &lt;br /&gt;
 ssl_cert = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 ssl_key = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 #leave the following commented for normal configuration&lt;br /&gt;
 #ssl_ca = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/chain.pem&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can configure different users for SMTP and IMAP or enable/disable SMTP for IMAP users.&lt;br /&gt;
The table structure created above have fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting smtp_enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND smtp_enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Verify SSL connections===&lt;br /&gt;
====SMTP starttls====&lt;br /&gt;
 openssl s_client -starttls smtp -servername server08.vettore.org -connect server08.vettore.org:587&lt;br /&gt;
====IMAP startls==== &lt;br /&gt;
 openssl s_client -starttls imap -servername server08.vettore.org -connect server08.vettore.org:143&lt;br /&gt;
&lt;br /&gt;
==Sieve/pidgeonhole (optional)==&lt;br /&gt;
 dnf install dovecot-pigeonhole&lt;br /&gt;
&lt;br /&gt;
edit ./conf.d/20-lmtp.conf &amp;amp; uncomment&lt;br /&gt;
 mail_plugins = $mail_plugins sievement&lt;br /&gt;
&lt;br /&gt;
edit ./conf.d/20-managesieve.conf and uncomment &lt;br /&gt;
 iprotocols = $protocols sieve&lt;br /&gt;
&lt;br /&gt;
and&lt;br /&gt;
 service managesieve-login {&lt;br /&gt;
  inet_listener sieve {&lt;br /&gt;
    port = 4190&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
restart dovecot&amp;lt;/br&amp;gt;&lt;br /&gt;
Try to telnet your local port 4190 to check if managesieve service is running&amp;lt;/br&amp;gt;&lt;br /&gt;
Enable LMTP in ./conf/10-master.conf&lt;br /&gt;
&lt;br /&gt;
 service lmtp {&lt;br /&gt;
 unix_listener /var/spool/postfix/private/dovecot-lmtp {&lt;br /&gt;
    group = postfix&lt;br /&gt;
    mode = 0600&lt;br /&gt;
    user = postfix&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
in /etc/postfix/main.cf edit the virtual_transport&lt;br /&gt;
 virtual_transport = lmtp:unix:/var/spool/postfix/private/dovecot-lmtp&lt;br /&gt;
&lt;br /&gt;
restart both postfix and dovecot&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=236</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=236"/>
		<updated>2025-10-16T08:05:41Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Sieve/pidgeonhole (optional)= */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Quick and dirty (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===Prerequisites===&lt;br /&gt;
configure your DNS properly&lt;br /&gt;
*A record matching the FQDN of this server&lt;br /&gt;
*MX record for the domains to the IP of this server&lt;br /&gt;
*ensure reverse IP is configured properly or some external servers can refuse your email&lt;br /&gt;
*not mandatory: SPF record for your domains matching with the IP of your server&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQDN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
====USERS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
There are more fields than in usual tutorials you can retrieve online. &lt;br /&gt;
*enabled: user can receive emails&lt;br /&gt;
*imap_enabled: user can retieve email with IMAPs protocol&lt;br /&gt;
*smtp_enabled: user can use smtp service to send email from a remote client&lt;br /&gt;
*smtp_username: to authenticate SMTP, can be different from the email address&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
====DOMAINS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
====ALIASES====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, smtp_username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 dovecot_destination_recipient_limit = 1&lt;br /&gt;
 &lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtpd_tls_security_level = may&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/server08.vettore.org&lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/chain.pem&lt;br /&gt;
 &lt;br /&gt;
 smtpd_client_restrictions = permit_mynetworks,&lt;br /&gt;
        permit_sasl_authenticated,&lt;br /&gt;
        reject_unauth_destination,&lt;br /&gt;
        reject_unknown_sender_domain,&lt;br /&gt;
        reject_unknown_reverse_client_hostname,&lt;br /&gt;
        reject_rbl_client b.barracudacentral.org,&lt;br /&gt;
        reject_rbl_client blackholes.easynet.nl,&lt;br /&gt;
        reject_rbl_client proxies.blackholes.wirehub.net,&lt;br /&gt;
        reject_rbl_client bl.spamcop.net,&lt;br /&gt;
  &lt;br /&gt;
 #disabled for several reasons (be careful to enable again)&lt;br /&gt;
 &lt;br /&gt;
 #       reject_rbl_client sbl.spamhaus.org,&lt;br /&gt;
 #        reject_rbl_client zen.spamhaus.org,&lt;br /&gt;
 #        reject_rhsbl_sender blackhole.securitysage.com,&lt;br /&gt;
 #        reject_rbl_client cbl.abuseat.org,&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above (virtual_xxx)&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Edit  /etc/dovecot/conf.d/10-auth.conf:&amp;lt;br&amp;gt;&lt;br /&gt;
Enable loading of the above file removing comment from &lt;br /&gt;
 !include auth-sql.conf.ext&lt;br /&gt;
and comment out in order to disable PAM (otherwise you will get errors in /var/log/secure)&lt;br /&gt;
 #!include auth-system.conf.ext&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the /etc/dovecot/conf.d/auth-sql.conf.ext file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND imap_enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above &lt;br /&gt;
 ssl_cert = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 ssl_key = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 #leave the following commented for normal configuration&lt;br /&gt;
 #ssl_ca = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/chain.pem&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can configure different users for SMTP and IMAP or enable/disable SMTP for IMAP users.&lt;br /&gt;
The table structure created above have fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting smtp_enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND smtp_enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Verify SSL connections===&lt;br /&gt;
====SMTP starttls====&lt;br /&gt;
 openssl s_client -starttls smtp -servername server08.vettore.org -connect server08.vettore.org:587&lt;br /&gt;
====IMAP startls==== &lt;br /&gt;
 openssl s_client -starttls imap -servername server08.vettore.org -connect server08.vettore.org:143&lt;br /&gt;
&lt;br /&gt;
==Sieve/pidgeonhole (optional)==&lt;br /&gt;
 dnf install dovecot-pigeonhole&lt;br /&gt;
&lt;br /&gt;
edit ./conf.d/20-lmtp.conf &amp;amp; uncomment&lt;br /&gt;
 mail_plugins = $mail_plugins sievement&lt;br /&gt;
&lt;br /&gt;
edit ./conf.d/20-managesieve.conf and uncomment &lt;br /&gt;
 iprotocols = $protocols sieve&lt;br /&gt;
&lt;br /&gt;
and&lt;br /&gt;
 service managesieve-login {&lt;br /&gt;
  inet_listener sieve {&lt;br /&gt;
    port = 4190&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
restart dovecot&amp;lt;/br&amp;gt;&lt;br /&gt;
Try to telnet your local port 4190 to check if managesieve service is running&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=235</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=235"/>
		<updated>2025-10-16T08:05:30Z</updated>

		<summary type="html">&lt;p&gt;Administrator: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Quick and dirty (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===Prerequisites===&lt;br /&gt;
configure your DNS properly&lt;br /&gt;
*A record matching the FQDN of this server&lt;br /&gt;
*MX record for the domains to the IP of this server&lt;br /&gt;
*ensure reverse IP is configured properly or some external servers can refuse your email&lt;br /&gt;
*not mandatory: SPF record for your domains matching with the IP of your server&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQDN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
====USERS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
There are more fields than in usual tutorials you can retrieve online. &lt;br /&gt;
*enabled: user can receive emails&lt;br /&gt;
*imap_enabled: user can retieve email with IMAPs protocol&lt;br /&gt;
*smtp_enabled: user can use smtp service to send email from a remote client&lt;br /&gt;
*smtp_username: to authenticate SMTP, can be different from the email address&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
====DOMAINS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
====ALIASES====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, smtp_username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 dovecot_destination_recipient_limit = 1&lt;br /&gt;
 &lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtpd_tls_security_level = may&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/server08.vettore.org&lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/chain.pem&lt;br /&gt;
 &lt;br /&gt;
 smtpd_client_restrictions = permit_mynetworks,&lt;br /&gt;
        permit_sasl_authenticated,&lt;br /&gt;
        reject_unauth_destination,&lt;br /&gt;
        reject_unknown_sender_domain,&lt;br /&gt;
        reject_unknown_reverse_client_hostname,&lt;br /&gt;
        reject_rbl_client b.barracudacentral.org,&lt;br /&gt;
        reject_rbl_client blackholes.easynet.nl,&lt;br /&gt;
        reject_rbl_client proxies.blackholes.wirehub.net,&lt;br /&gt;
        reject_rbl_client bl.spamcop.net,&lt;br /&gt;
  &lt;br /&gt;
 #disabled for several reasons (be careful to enable again)&lt;br /&gt;
 &lt;br /&gt;
 #       reject_rbl_client sbl.spamhaus.org,&lt;br /&gt;
 #        reject_rbl_client zen.spamhaus.org,&lt;br /&gt;
 #        reject_rhsbl_sender blackhole.securitysage.com,&lt;br /&gt;
 #        reject_rbl_client cbl.abuseat.org,&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above (virtual_xxx)&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Edit  /etc/dovecot/conf.d/10-auth.conf:&amp;lt;br&amp;gt;&lt;br /&gt;
Enable loading of the above file removing comment from &lt;br /&gt;
 !include auth-sql.conf.ext&lt;br /&gt;
and comment out in order to disable PAM (otherwise you will get errors in /var/log/secure)&lt;br /&gt;
 #!include auth-system.conf.ext&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the /etc/dovecot/conf.d/auth-sql.conf.ext file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND imap_enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above &lt;br /&gt;
 ssl_cert = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 ssl_key = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 #leave the following commented for normal configuration&lt;br /&gt;
 #ssl_ca = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/chain.pem&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can configure different users for SMTP and IMAP or enable/disable SMTP for IMAP users.&lt;br /&gt;
The table structure created above have fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting smtp_enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND smtp_enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Verify SSL connections===&lt;br /&gt;
====SMTP starttls====&lt;br /&gt;
 openssl s_client -starttls smtp -servername server08.vettore.org -connect server08.vettore.org:587&lt;br /&gt;
====IMAP startls==== &lt;br /&gt;
 openssl s_client -starttls imap -servername server08.vettore.org -connect server08.vettore.org:143&lt;br /&gt;
&lt;br /&gt;
==Sieve/pidgeonhole (optional)===&lt;br /&gt;
 dnf install dovecot-pigeonhole&lt;br /&gt;
&lt;br /&gt;
edit ./conf.d/20-lmtp.conf &amp;amp; uncomment&lt;br /&gt;
 mail_plugins = $mail_plugins sievement&lt;br /&gt;
&lt;br /&gt;
edit ./conf.d/20-managesieve.conf and uncomment &lt;br /&gt;
 iprotocols = $protocols sieve&lt;br /&gt;
&lt;br /&gt;
and&lt;br /&gt;
 service managesieve-login {&lt;br /&gt;
  inet_listener sieve {&lt;br /&gt;
    port = 4190&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
restart dovecot&amp;lt;/br&amp;gt;&lt;br /&gt;
Try to telnet your local port 4190 to check if managesieve service is running&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=234</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=234"/>
		<updated>2025-10-15T05:50:22Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Dovecot IMAP */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Quick and dirty (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===Prerequisites===&lt;br /&gt;
configure your DNS properly&lt;br /&gt;
*A record matching the FQDN of this server&lt;br /&gt;
*MX record for the domains to the IP of this server&lt;br /&gt;
*ensure reverse IP is configured properly or some external servers can refuse your email&lt;br /&gt;
*not mandatory: SPF record for your domains matching with the IP of your server&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQDN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
====USERS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
There are more fields than in usual tutorials you can retrieve online. &lt;br /&gt;
*enabled: user can receive emails&lt;br /&gt;
*imap_enabled: user can retieve email with IMAPs protocol&lt;br /&gt;
*smtp_enabled: user can use smtp service to send email from a remote client&lt;br /&gt;
*smtp_username: to authenticate SMTP, can be different from the email address&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
====DOMAINS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
====ALIASES====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, smtp_username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 dovecot_destination_recipient_limit = 1&lt;br /&gt;
 &lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtpd_tls_security_level = may&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/server08.vettore.org&lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/chain.pem&lt;br /&gt;
 &lt;br /&gt;
 smtpd_client_restrictions = permit_mynetworks,&lt;br /&gt;
        permit_sasl_authenticated,&lt;br /&gt;
        reject_unauth_destination,&lt;br /&gt;
        reject_unknown_sender_domain,&lt;br /&gt;
        reject_unknown_reverse_client_hostname,&lt;br /&gt;
        reject_rbl_client b.barracudacentral.org,&lt;br /&gt;
        reject_rbl_client blackholes.easynet.nl,&lt;br /&gt;
        reject_rbl_client proxies.blackholes.wirehub.net,&lt;br /&gt;
        reject_rbl_client bl.spamcop.net,&lt;br /&gt;
  &lt;br /&gt;
 #disabled for several reasons (be careful to enable again)&lt;br /&gt;
 &lt;br /&gt;
 #       reject_rbl_client sbl.spamhaus.org,&lt;br /&gt;
 #        reject_rbl_client zen.spamhaus.org,&lt;br /&gt;
 #        reject_rhsbl_sender blackhole.securitysage.com,&lt;br /&gt;
 #        reject_rbl_client cbl.abuseat.org,&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above (virtual_xxx)&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Edit  /etc/dovecot/conf.d/10-auth.conf:&amp;lt;br&amp;gt;&lt;br /&gt;
Enable loading of the above file removing comment from &lt;br /&gt;
 !include auth-sql.conf.ext&lt;br /&gt;
and comment out in order to disable PAM (otherwise you will get errors in /var/log/secure)&lt;br /&gt;
 #!include auth-system.conf.ext&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the /etc/dovecot/conf.d/auth-sql.conf.ext file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND imap_enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above &lt;br /&gt;
 ssl_cert = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 ssl_key = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 #leave the following commented for normal configuration&lt;br /&gt;
 #ssl_ca = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/chain.pem&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can configure different users for SMTP and IMAP or enable/disable SMTP for IMAP users.&lt;br /&gt;
The table structure created above have fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting smtp_enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND smtp_enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Verify SSL connections===&lt;br /&gt;
====SMTP starttls====&lt;br /&gt;
 openssl s_client -starttls smtp -servername server08.vettore.org -connect server08.vettore.org:587&lt;br /&gt;
====IMAP startls==== &lt;br /&gt;
 openssl s_client -starttls imap -servername server08.vettore.org -connect server08.vettore.org:143&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=233</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=233"/>
		<updated>2025-10-14T05:52:38Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Dovecot IMAP */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Quick and dirty (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===Prerequisites===&lt;br /&gt;
configure your DNS properly&lt;br /&gt;
*A record matching the FQDN of this server&lt;br /&gt;
*MX record for the domains to the IP of this server&lt;br /&gt;
*ensure reverse IP is configured properly or some external servers can refuse your email&lt;br /&gt;
*not mandatory: SPF record for your domains matching with the IP of your server&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQDN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
====USERS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
There are more fields than in usual tutorials you can retrieve online. &lt;br /&gt;
*enabled: user can receive emails&lt;br /&gt;
*imap_enabled: user can retieve email with IMAPs protocol&lt;br /&gt;
*smtp_enabled: user can use smtp service to send email from a remote client&lt;br /&gt;
*smtp_username: to authenticate SMTP, can be different from the email address&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
====DOMAINS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
====ALIASES====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, smtp_username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 dovecot_destination_recipient_limit = 1&lt;br /&gt;
 &lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtpd_tls_security_level = may&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/server08.vettore.org&lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/chain.pem&lt;br /&gt;
 &lt;br /&gt;
 smtpd_client_restrictions = permit_mynetworks,&lt;br /&gt;
        permit_sasl_authenticated,&lt;br /&gt;
        reject_unauth_destination,&lt;br /&gt;
        reject_unknown_sender_domain,&lt;br /&gt;
        reject_unknown_reverse_client_hostname,&lt;br /&gt;
        reject_rbl_client b.barracudacentral.org,&lt;br /&gt;
        reject_rbl_client blackholes.easynet.nl,&lt;br /&gt;
        reject_rbl_client proxies.blackholes.wirehub.net,&lt;br /&gt;
        reject_rbl_client bl.spamcop.net,&lt;br /&gt;
  &lt;br /&gt;
 #disabled for several reasons (be careful to enable again)&lt;br /&gt;
 &lt;br /&gt;
 #       reject_rbl_client sbl.spamhaus.org,&lt;br /&gt;
 #        reject_rbl_client zen.spamhaus.org,&lt;br /&gt;
 #        reject_rhsbl_sender blackhole.securitysage.com,&lt;br /&gt;
 #        reject_rbl_client cbl.abuseat.org,&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above (virtual_xxx)&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND imap_enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above &lt;br /&gt;
 ssl_cert = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 ssl_key = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 #leave the following commented for normal configuration&lt;br /&gt;
 #ssl_ca = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/chain.pem&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Disable PAM auth (otherwise you will get errors in /var/log/secure.&amp;lt;/br&amp;gt;&lt;br /&gt;
Comment out the following in /etc/dovecot/conf.d/10-auth.conf&lt;br /&gt;
 #!include auth-system.conf.ext&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can configure different users for SMTP and IMAP or enable/disable SMTP for IMAP users.&lt;br /&gt;
The table structure created above have fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting smtp_enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND smtp_enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Verify SSL connections===&lt;br /&gt;
====SMTP starttls====&lt;br /&gt;
 openssl s_client -starttls smtp -servername server08.vettore.org -connect server08.vettore.org:587&lt;br /&gt;
====IMAP startls==== &lt;br /&gt;
 openssl s_client -starttls imap -servername server08.vettore.org -connect server08.vettore.org:143&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=232</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=232"/>
		<updated>2025-10-14T05:52:03Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Dovecot IMAP */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Quick and dirty (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===Prerequisites===&lt;br /&gt;
configure your DNS properly&lt;br /&gt;
*A record matching the FQDN of this server&lt;br /&gt;
*MX record for the domains to the IP of this server&lt;br /&gt;
*ensure reverse IP is configured properly or some external servers can refuse your email&lt;br /&gt;
*not mandatory: SPF record for your domains matching with the IP of your server&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQDN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
====USERS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
There are more fields than in usual tutorials you can retrieve online. &lt;br /&gt;
*enabled: user can receive emails&lt;br /&gt;
*imap_enabled: user can retieve email with IMAPs protocol&lt;br /&gt;
*smtp_enabled: user can use smtp service to send email from a remote client&lt;br /&gt;
*smtp_username: to authenticate SMTP, can be different from the email address&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
====DOMAINS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
====ALIASES====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, smtp_username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 dovecot_destination_recipient_limit = 1&lt;br /&gt;
 &lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtpd_tls_security_level = may&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/server08.vettore.org&lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/chain.pem&lt;br /&gt;
 &lt;br /&gt;
 smtpd_client_restrictions = permit_mynetworks,&lt;br /&gt;
        permit_sasl_authenticated,&lt;br /&gt;
        reject_unauth_destination,&lt;br /&gt;
        reject_unknown_sender_domain,&lt;br /&gt;
        reject_unknown_reverse_client_hostname,&lt;br /&gt;
        reject_rbl_client b.barracudacentral.org,&lt;br /&gt;
        reject_rbl_client blackholes.easynet.nl,&lt;br /&gt;
        reject_rbl_client proxies.blackholes.wirehub.net,&lt;br /&gt;
        reject_rbl_client bl.spamcop.net,&lt;br /&gt;
  &lt;br /&gt;
 #disabled for several reasons (be careful to enable again)&lt;br /&gt;
 &lt;br /&gt;
 #       reject_rbl_client sbl.spamhaus.org,&lt;br /&gt;
 #        reject_rbl_client zen.spamhaus.org,&lt;br /&gt;
 #        reject_rhsbl_sender blackhole.securitysage.com,&lt;br /&gt;
 #        reject_rbl_client cbl.abuseat.org,&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above (virtual_xxx)&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND imap_enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above &lt;br /&gt;
 ssl_cert = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 ssl_key = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 #leave the following commented for normal configuration&lt;br /&gt;
 #ssl_ca = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/chain.pem&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Disable PAM auth (otherwise you will get errirs in /var/log/secure.&amp;lt;/br&amp;gt;&lt;br /&gt;
Comment out the following in /etc/dovecot/conf.d/10-auth.conf&lt;br /&gt;
 #!include auth-system.conf.ext&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can configure different users for SMTP and IMAP or enable/disable SMTP for IMAP users.&lt;br /&gt;
The table structure created above have fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting smtp_enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND smtp_enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Verify SSL connections===&lt;br /&gt;
====SMTP starttls====&lt;br /&gt;
 openssl s_client -starttls smtp -servername server08.vettore.org -connect server08.vettore.org:587&lt;br /&gt;
====IMAP startls==== &lt;br /&gt;
 openssl s_client -starttls imap -servername server08.vettore.org -connect server08.vettore.org:143&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=231</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=231"/>
		<updated>2025-10-10T13:24:54Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Postfix */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Quick and dirty (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===Prerequisites===&lt;br /&gt;
configure your DNS properly&lt;br /&gt;
*A record matching the FQDN of this server&lt;br /&gt;
*MX record for the domains to the IP of this server&lt;br /&gt;
*ensure reverse IP is configured properly or some external servers can refuse your email&lt;br /&gt;
*not mandatory: SPF record for your domains matching with the IP of your server&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQDN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
====USERS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
There are more fields than in usual tutorials you can retrieve online. &lt;br /&gt;
*enabled: user can receive emails&lt;br /&gt;
*imap_enabled: user can retieve email with IMAPs protocol&lt;br /&gt;
*smtp_enabled: user can use smtp service to send email from a remote client&lt;br /&gt;
*smtp_username: to authenticate SMTP, can be different from the email address&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
====DOMAINS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
====ALIASES====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, smtp_username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 dovecot_destination_recipient_limit = 1&lt;br /&gt;
 &lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtpd_tls_security_level = may&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/server08.vettore.org&lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/chain.pem&lt;br /&gt;
 &lt;br /&gt;
 smtpd_client_restrictions = permit_mynetworks,&lt;br /&gt;
        permit_sasl_authenticated,&lt;br /&gt;
        reject_unauth_destination,&lt;br /&gt;
        reject_unknown_sender_domain,&lt;br /&gt;
        reject_unknown_reverse_client_hostname,&lt;br /&gt;
        reject_rbl_client b.barracudacentral.org,&lt;br /&gt;
        reject_rbl_client blackholes.easynet.nl,&lt;br /&gt;
        reject_rbl_client proxies.blackholes.wirehub.net,&lt;br /&gt;
        reject_rbl_client bl.spamcop.net,&lt;br /&gt;
  &lt;br /&gt;
 #disabled for several reasons (be careful to enable again)&lt;br /&gt;
 &lt;br /&gt;
 #       reject_rbl_client sbl.spamhaus.org,&lt;br /&gt;
 #        reject_rbl_client zen.spamhaus.org,&lt;br /&gt;
 #        reject_rhsbl_sender blackhole.securitysage.com,&lt;br /&gt;
 #        reject_rbl_client cbl.abuseat.org,&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above (virtual_xxx)&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND imap_enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above &lt;br /&gt;
 ssl_cert = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 ssl_key = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 #leave the following commented for normal configuration&lt;br /&gt;
 #ssl_ca = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/chain.pem&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can configure different users for SMTP and IMAP or enable/disable SMTP for IMAP users.&lt;br /&gt;
The table structure created above have fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting smtp_enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND smtp_enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Verify SSL connections===&lt;br /&gt;
====SMTP starttls====&lt;br /&gt;
 openssl s_client -starttls smtp -servername server08.vettore.org -connect server08.vettore.org:587&lt;br /&gt;
====IMAP startls==== &lt;br /&gt;
 openssl s_client -starttls imap -servername server08.vettore.org -connect server08.vettore.org:143&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=230</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=230"/>
		<updated>2025-10-09T13:40:57Z</updated>

		<summary type="html">&lt;p&gt;Administrator: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Quick and dirty (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===Prerequisites===&lt;br /&gt;
configure your DNS properly&lt;br /&gt;
*A record matching the FQDN of this server&lt;br /&gt;
*MX record for the domains to the IP of this server&lt;br /&gt;
*ensure reverse IP is configured properly or some external servers can refuse your email&lt;br /&gt;
*not mandatory: SPF record for your domains matching with the IP of your server&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQDN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
====USERS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
There are more fields than in usual tutorials you can retrieve online. &lt;br /&gt;
*enabled: user can receive emails&lt;br /&gt;
*imap_enabled: user can retieve email with IMAPs protocol&lt;br /&gt;
*smtp_enabled: user can use smtp service to send email from a remote client&lt;br /&gt;
*smtp_username: to authenticate SMTP, can be different from the email address&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
====DOMAINS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
====ALIASES====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, smtp_username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtpd_tls_security_level = may&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/server08.vettore.org&lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/chain.pem&lt;br /&gt;
 &lt;br /&gt;
 smtpd_client_restrictions = permit_mynetworks,&lt;br /&gt;
        permit_sasl_authenticated,&lt;br /&gt;
        reject_unauth_destination,&lt;br /&gt;
        reject_unknown_sender_domain,&lt;br /&gt;
        reject_unknown_reverse_client_hostname,&lt;br /&gt;
        reject_rbl_client b.barracudacentral.org,&lt;br /&gt;
        reject_rbl_client blackholes.easynet.nl,&lt;br /&gt;
        reject_rbl_client proxies.blackholes.wirehub.net,&lt;br /&gt;
        reject_rbl_client bl.spamcop.net,&lt;br /&gt;
  &lt;br /&gt;
 #disabled for several reasons (be careful to enable again)&lt;br /&gt;
 &lt;br /&gt;
 #       reject_rbl_client sbl.spamhaus.org,&lt;br /&gt;
 #        reject_rbl_client zen.spamhaus.org,&lt;br /&gt;
 #        reject_rhsbl_sender blackhole.securitysage.com,&lt;br /&gt;
 #        reject_rbl_client cbl.abuseat.org,&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above (virtual_xxx)&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND imap_enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above &lt;br /&gt;
 ssl_cert = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 ssl_key = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 #leave the following commented for normal configuration&lt;br /&gt;
 #ssl_ca = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/chain.pem&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can configure different users for SMTP and IMAP or enable/disable SMTP for IMAP users.&lt;br /&gt;
The table structure created above have fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting smtp_enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND smtp_enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Verify SSL connections===&lt;br /&gt;
====SMTP starttls====&lt;br /&gt;
 openssl s_client -starttls smtp -servername server08.vettore.org -connect server08.vettore.org:587&lt;br /&gt;
====IMAP startls==== &lt;br /&gt;
 openssl s_client -starttls imap -servername server08.vettore.org -connect server08.vettore.org:143&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=229</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=229"/>
		<updated>2025-10-09T13:26:38Z</updated>

		<summary type="html">&lt;p&gt;Administrator: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Quick and dirty (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===Prerequisites===&lt;br /&gt;
configure your DNS properly&lt;br /&gt;
*A record matching the FQDN of this server&lt;br /&gt;
*MX record for the domains to the IP of this server&lt;br /&gt;
*ensure reverse IP is configured properly or some external servers can refuse your email&lt;br /&gt;
*not mandatory: SPF record for your domains matching with the IP of your server&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQDN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
====USERS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
There are more fields than in usual tutorials you can retrieve online. &lt;br /&gt;
*enabled: user can receive emails&lt;br /&gt;
*imap_enabled: user can retieve email with IMAPs protocol&lt;br /&gt;
*smtp_enabled: user can use smtp service to send email from a remote client&lt;br /&gt;
*smtp_username: to authenticate SMTP, can be different from the email address&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
====DOMAINS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
====ALIASES====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, smtp_username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtpd_tls_security_level = may&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/server08.vettore.org&lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/chain.pem&lt;br /&gt;
 &lt;br /&gt;
 smtpd_client_restrictions = permit_mynetworks,&lt;br /&gt;
        permit_sasl_authenticated,&lt;br /&gt;
        reject_unauth_destination,&lt;br /&gt;
        reject_unknown_sender_domain,&lt;br /&gt;
        reject_unknown_reverse_client_hostname,&lt;br /&gt;
        reject_rbl_client b.barracudacentral.org,&lt;br /&gt;
        reject_rbl_client blackholes.easynet.nl,&lt;br /&gt;
        reject_rbl_client proxies.blackholes.wirehub.net,&lt;br /&gt;
        reject_rbl_client bl.spamcop.net,&lt;br /&gt;
  &lt;br /&gt;
 #disabled for several reasons (be careful to enable again)&lt;br /&gt;
 &lt;br /&gt;
 #       reject_rbl_client sbl.spamhaus.org,&lt;br /&gt;
 #        reject_rbl_client zen.spamhaus.org,&lt;br /&gt;
 #        reject_rhsbl_sender blackhole.securitysage.com,&lt;br /&gt;
 #        reject_rbl_client cbl.abuseat.org,&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above (virtual_xxx)&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND imap_enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above &lt;br /&gt;
 ssl_cert = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 ssl_key = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 ssl_ca = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/chain.pem&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can configure different users for SMTP and IMAP or enable/disable SMTP for IMAP users.&lt;br /&gt;
The table structure created above have fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting smtp_enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND smtp_enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Verify SSL connections===&lt;br /&gt;
====SMTP starttls====&lt;br /&gt;
 openssl s_client -starttls smtp -servername server08.vettore.org -connect server08.vettore.org:587&lt;br /&gt;
====IMAP startls==== &lt;br /&gt;
 openssl s_client -starttls imap -servername server08.vettore.org -connect server08.vettore.org:143&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=228</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=228"/>
		<updated>2025-10-09T13:23:40Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Postfix */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Quick and dirty (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===Prerequisites===&lt;br /&gt;
configure your DNS properly&lt;br /&gt;
*A record matching the FQDN of this server&lt;br /&gt;
*MX record for the domains to the IP of this server&lt;br /&gt;
*ensure reverse IP is configured properly or some external servers can refuse your email&lt;br /&gt;
*not mandatory: SPF record for your domains matching with the IP of your server&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQDN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
====USERS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
There are more fields than in usual tutorials you can retrieve online. &lt;br /&gt;
*enabled: user can receive emails&lt;br /&gt;
*imap_enabled: user can retieve email with IMAPs protocol&lt;br /&gt;
*smtp_enabled: user can use smtp service to send email from a remote client&lt;br /&gt;
*smtp_username: to authenticate SMTP, can be different from the email address&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
====DOMAINS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
====ALIASES====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, smtp_username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtpd_tls_security_level = may&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/server08.vettore.org&lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/chain.pem&lt;br /&gt;
 &lt;br /&gt;
 smtpd_client_restrictions = permit_mynetworks,&lt;br /&gt;
        permit_sasl_authenticated,&lt;br /&gt;
        reject_unauth_destination,&lt;br /&gt;
        reject_unknown_sender_domain,&lt;br /&gt;
        reject_unknown_reverse_client_hostname,&lt;br /&gt;
        reject_rbl_client b.barracudacentral.org,&lt;br /&gt;
        reject_rbl_client blackholes.easynet.nl,&lt;br /&gt;
        reject_rbl_client proxies.blackholes.wirehub.net,&lt;br /&gt;
        reject_rbl_client bl.spamcop.net,&lt;br /&gt;
  &lt;br /&gt;
 #disabled for several reasons (be careful to enable again)&lt;br /&gt;
 &lt;br /&gt;
 #       reject_rbl_client sbl.spamhaus.org,&lt;br /&gt;
 #        reject_rbl_client zen.spamhaus.org,&lt;br /&gt;
 #        reject_rhsbl_sender blackhole.securitysage.com,&lt;br /&gt;
 #        reject_rbl_client cbl.abuseat.org,&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above (virtual_xxx)&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND imap_enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above &lt;br /&gt;
 ssl_cert = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 ssl_key = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 ssl_ca = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/chain.pem&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can configure different users for SMTP and IMAP or enable/disable SMTP for IMAP users.&lt;br /&gt;
The table structure created above have fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting smtp_enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND smtp_enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=227</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=227"/>
		<updated>2025-10-09T13:19:34Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Dovecot IMAP */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Quick and dirty (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===Prerequisites===&lt;br /&gt;
configure your DNS properly&lt;br /&gt;
*A record matching the FQDN of this server&lt;br /&gt;
*MX record for the domains to the IP of this server&lt;br /&gt;
*ensure reverse IP is configured properly or some external servers can refuse your email&lt;br /&gt;
*not mandatory: SPF record for your domains matching with the IP of your server&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQDN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
====USERS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
There are more fields than in usual tutorials you can retrieve online. &lt;br /&gt;
*enabled: user can receive emails&lt;br /&gt;
*imap_enabled: user can retieve email with IMAPs protocol&lt;br /&gt;
*smtp_enabled: user can use smtp service to send email from a remote client&lt;br /&gt;
*smtp_username: to authenticate SMTP, can be different from the email address&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
====DOMAINS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
====ALIASES====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, smtp_username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 smtpd_client_restrictions = permit_mynetworks,&lt;br /&gt;
        permit_sasl_authenticated,&lt;br /&gt;
        reject_unauth_destination,&lt;br /&gt;
        reject_unknown_sender_domain,&lt;br /&gt;
        reject_unknown_reverse_client_hostname,&lt;br /&gt;
        reject_rbl_client b.barracudacentral.org,&lt;br /&gt;
        reject_rbl_client blackholes.easynet.nl,&lt;br /&gt;
        reject_rbl_client proxies.blackholes.wirehub.net,&lt;br /&gt;
        reject_rbl_client bl.spamcop.net,&lt;br /&gt;
  &lt;br /&gt;
 #disabled for several reasons (be careful to enable again)&lt;br /&gt;
 &lt;br /&gt;
 #       reject_rbl_client sbl.spamhaus.org,&lt;br /&gt;
 #        reject_rbl_client zen.spamhaus.org,&lt;br /&gt;
 #        reject_rhsbl_sender blackhole.securitysage.com,&lt;br /&gt;
 #        reject_rbl_client cbl.abuseat.org,&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above (virtual_xxx)&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND imap_enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above &lt;br /&gt;
 ssl_cert = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 ssl_key = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 ssl_ca = &amp;lt;/etc/letsencrypt/live/server08.vettore.org/chain.pem&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can configure different users for SMTP and IMAP or enable/disable SMTP for IMAP users.&lt;br /&gt;
The table structure created above have fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting smtp_enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND smtp_enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=226</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=226"/>
		<updated>2025-10-09T06:39:25Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Prerequisites= */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Quick and dirty (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===Prerequisites===&lt;br /&gt;
configure your DNS properly&lt;br /&gt;
*A record matching the FQDN of this server&lt;br /&gt;
*MX record for the domains to the IP of this server&lt;br /&gt;
*ensure reverse IP is configured properly or some external servers can refuse your email&lt;br /&gt;
*not mandatory: SPF record for your domains matching with the IP of your server&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQDN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
====USERS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
There are more fields than in usual tutorials you can retrieve online. &lt;br /&gt;
*enabled: user can receive emails&lt;br /&gt;
*imap_enabled: user can retieve email with IMAPs protocol&lt;br /&gt;
*smtp_enabled: user can use smtp service to send email from a remote client&lt;br /&gt;
*smtp_username: to authenticate SMTP, can be different from the email address&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
====DOMAINS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
====ALIASES====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, smtp_username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 smtpd_client_restrictions = permit_mynetworks,&lt;br /&gt;
        permit_sasl_authenticated,&lt;br /&gt;
        reject_unauth_destination,&lt;br /&gt;
        reject_unknown_sender_domain,&lt;br /&gt;
        reject_unknown_reverse_client_hostname,&lt;br /&gt;
        reject_rbl_client b.barracudacentral.org,&lt;br /&gt;
        reject_rbl_client blackholes.easynet.nl,&lt;br /&gt;
        reject_rbl_client proxies.blackholes.wirehub.net,&lt;br /&gt;
        reject_rbl_client bl.spamcop.net,&lt;br /&gt;
  &lt;br /&gt;
 #disabled for several reasons (be careful to enable again)&lt;br /&gt;
 &lt;br /&gt;
 #       reject_rbl_client sbl.spamhaus.org,&lt;br /&gt;
 #        reject_rbl_client zen.spamhaus.org,&lt;br /&gt;
 #        reject_rhsbl_sender blackhole.securitysage.com,&lt;br /&gt;
 #        reject_rbl_client cbl.abuseat.org,&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above (virtual_xxx)&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND imap_enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can configure different users for SMTP and IMAP or enable/disable SMTP for IMAP users.&lt;br /&gt;
The table structure created above have fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting smtp_enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND smtp_enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=225</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=225"/>
		<updated>2025-10-09T06:39:16Z</updated>

		<summary type="html">&lt;p&gt;Administrator: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Quick and dirty (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===Prerequisites====&lt;br /&gt;
configure your DNS properly&lt;br /&gt;
*A record matching the FQDN of this server&lt;br /&gt;
*MX record for the domains to the IP of this server&lt;br /&gt;
*ensure reverse IP is configured properly or some external servers can refuse your email&lt;br /&gt;
*not mandatory: SPF record for your domains matching with the IP of your server &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQDN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
====USERS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
There are more fields than in usual tutorials you can retrieve online. &lt;br /&gt;
*enabled: user can receive emails&lt;br /&gt;
*imap_enabled: user can retieve email with IMAPs protocol&lt;br /&gt;
*smtp_enabled: user can use smtp service to send email from a remote client&lt;br /&gt;
*smtp_username: to authenticate SMTP, can be different from the email address&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
====DOMAINS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
====ALIASES====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, smtp_username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 smtpd_client_restrictions = permit_mynetworks,&lt;br /&gt;
        permit_sasl_authenticated,&lt;br /&gt;
        reject_unauth_destination,&lt;br /&gt;
        reject_unknown_sender_domain,&lt;br /&gt;
        reject_unknown_reverse_client_hostname,&lt;br /&gt;
        reject_rbl_client b.barracudacentral.org,&lt;br /&gt;
        reject_rbl_client blackholes.easynet.nl,&lt;br /&gt;
        reject_rbl_client proxies.blackholes.wirehub.net,&lt;br /&gt;
        reject_rbl_client bl.spamcop.net,&lt;br /&gt;
  &lt;br /&gt;
 #disabled for several reasons (be careful to enable again)&lt;br /&gt;
 &lt;br /&gt;
 #       reject_rbl_client sbl.spamhaus.org,&lt;br /&gt;
 #        reject_rbl_client zen.spamhaus.org,&lt;br /&gt;
 #        reject_rhsbl_sender blackhole.securitysage.com,&lt;br /&gt;
 #        reject_rbl_client cbl.abuseat.org,&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above (virtual_xxx)&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND imap_enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can configure different users for SMTP and IMAP or enable/disable SMTP for IMAP users.&lt;br /&gt;
The table structure created above have fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting smtp_enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND smtp_enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=224</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=224"/>
		<updated>2025-10-09T06:33:23Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Postfix */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Quick and dirty (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQDN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
====USERS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
There are more fields than in usual tutorials you can retrieve online. &lt;br /&gt;
*enabled: user can receive emails&lt;br /&gt;
*imap_enabled: user can retieve email with IMAPs protocol&lt;br /&gt;
*smtp_enabled: user can use smtp service to send email from a remote client&lt;br /&gt;
*smtp_username: to authenticate SMTP, can be different from the email address&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
====DOMAINS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
====ALIASES====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, smtp_username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
 smtpd_client_restrictions = permit_mynetworks,&lt;br /&gt;
        permit_sasl_authenticated,&lt;br /&gt;
        reject_unauth_destination,&lt;br /&gt;
        reject_unknown_sender_domain,&lt;br /&gt;
        reject_unknown_reverse_client_hostname,&lt;br /&gt;
        reject_rbl_client b.barracudacentral.org,&lt;br /&gt;
        reject_rbl_client blackholes.easynet.nl,&lt;br /&gt;
        reject_rbl_client proxies.blackholes.wirehub.net,&lt;br /&gt;
        reject_rbl_client bl.spamcop.net,&lt;br /&gt;
  &lt;br /&gt;
 #disabled for several reasons (be careful to enable again)&lt;br /&gt;
 &lt;br /&gt;
 #       reject_rbl_client sbl.spamhaus.org,&lt;br /&gt;
 #        reject_rbl_client zen.spamhaus.org,&lt;br /&gt;
 #        reject_rhsbl_sender blackhole.securitysage.com,&lt;br /&gt;
 #        reject_rbl_client cbl.abuseat.org,&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above (virtual_xxx)&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND imap_enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can configure different users for SMTP and IMAP or enable/disable SMTP for IMAP users.&lt;br /&gt;
The table structure created above have fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting smtp_enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND smtp_enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=223</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=223"/>
		<updated>2025-10-09T06:31:39Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* SMTP auth with cyrus-sasl */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Quick and dirty (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQDN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
====USERS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
There are more fields than in usual tutorials you can retrieve online. &lt;br /&gt;
*enabled: user can receive emails&lt;br /&gt;
*imap_enabled: user can retieve email with IMAPs protocol&lt;br /&gt;
*smtp_enabled: user can use smtp service to send email from a remote client&lt;br /&gt;
*smtp_username: to authenticate SMTP, can be different from the email address&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
====DOMAINS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
====ALIASES====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, smtp_username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above (virtual_xxx)&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND imap_enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can configure different users for SMTP and IMAP or enable/disable SMTP for IMAP users.&lt;br /&gt;
The table structure created above have fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting smtp_enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND smtp_enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=222</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=222"/>
		<updated>2025-10-09T06:29:49Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Postfix */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Quick and dirty (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQDN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
====USERS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
There are more fields than in usual tutorials you can retrieve online. &lt;br /&gt;
*enabled: user can receive emails&lt;br /&gt;
*imap_enabled: user can retieve email with IMAPs protocol&lt;br /&gt;
*smtp_enabled: user can use smtp service to send email from a remote client&lt;br /&gt;
*smtp_username: to authenticate SMTP, can be different from the email address&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
====DOMAINS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
====ALIASES====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, smtp_username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above (virtual_xxx)&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND imap_enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can configure different users for SMTP and IMAP or enable/disable SMTPP for IMAP users.&lt;br /&gt;
The table structure created above have fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting smtp_enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND smtp_enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=221</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=221"/>
		<updated>2025-10-09T06:29:00Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* ALIAS */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Quick and dirty (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQDN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
====USERS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
There are more fields than in usual tutorials you can retrieve online. &lt;br /&gt;
*enabled: user can receive emails&lt;br /&gt;
*imap_enabled: user can retieve email with IMAPs protocol&lt;br /&gt;
*smtp_enabled: user can use smtp service to send email from a remote client&lt;br /&gt;
*smtp_username: to authenticate SMTP, can be different from the email address&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
====DOMAINS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
====ALIASES====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, smtp_username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND imap_enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can configure different users for SMTP and IMAP or enable/disable SMTPP for IMAP users.&lt;br /&gt;
The table structure created above have fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting smtp_enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND smtp_enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=220</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=220"/>
		<updated>2025-10-09T06:28:25Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* SSL certificates */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Quick and dirty (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQDN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
====USERS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
There are more fields than in usual tutorials you can retrieve online. &lt;br /&gt;
*enabled: user can receive emails&lt;br /&gt;
*imap_enabled: user can retieve email with IMAPs protocol&lt;br /&gt;
*smtp_enabled: user can use smtp service to send email from a remote client&lt;br /&gt;
*smtp_username: to authenticate SMTP, can be different from the email address&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
====DOMAINS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
====ALIAS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, smtp_username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND imap_enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can configure different users for SMTP and IMAP or enable/disable SMTPP for IMAP users.&lt;br /&gt;
The table structure created above have fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting smtp_enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND smtp_enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=219</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=219"/>
		<updated>2025-10-09T06:28:08Z</updated>

		<summary type="html">&lt;p&gt;Administrator: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Quick and dirty (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
====USERS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
There are more fields than in usual tutorials you can retrieve online. &lt;br /&gt;
*enabled: user can receive emails&lt;br /&gt;
*imap_enabled: user can retieve email with IMAPs protocol&lt;br /&gt;
*smtp_enabled: user can use smtp service to send email from a remote client&lt;br /&gt;
*smtp_username: to authenticate SMTP, can be different from the email address&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
====DOMAINS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
====ALIAS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, smtp_username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND imap_enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can configure different users for SMTP and IMAP or enable/disable SMTPP for IMAP users.&lt;br /&gt;
The table structure created above have fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting smtp_enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND smtp_enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=218</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=218"/>
		<updated>2025-10-09T06:27:41Z</updated>

		<summary type="html">&lt;p&gt;Administrator: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Dirty and quick (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
====USERS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
There are more fields than in usual tutorials you can retrieve online. &lt;br /&gt;
*enabled: user can receive emails&lt;br /&gt;
*imap_enabled: user can retieve email with IMAPs protocol&lt;br /&gt;
*smtp_enabled: user can use smtp service to send email from a remote client&lt;br /&gt;
*smtp_username: to authenticate SMTP, can be different from the email address&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
====DOMAINS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
====ALIAS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, smtp_username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND imap_enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can configure different users for SMTP and IMAP or enable/disable SMTPP for IMAP users.&lt;br /&gt;
The table structure created above have fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting smtp_enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND smtp_enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=217</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=217"/>
		<updated>2025-10-09T06:27:05Z</updated>

		<summary type="html">&lt;p&gt;Administrator: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Dirty and quick (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
====USERS====&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
There are more fields than in usual tutorials you can retrieve online. &lt;br /&gt;
*enabled: user can receive emails&lt;br /&gt;
*imap_enabled: user can retieve email with IMAPs protocol&lt;br /&gt;
*smtp_enabled: user can use smtp service to send email from a remote client&lt;br /&gt;
*smtp_username: to authenticate SMTP, can be different from the email address&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
DOMAINS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
ALIAS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, smtp_username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND imap_enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can configure different users for SMTP and IMAP or enable/disable SMTPP for IMAP users.&lt;br /&gt;
The table structure created above have fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting smtp_enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND smtp_enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=216</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=216"/>
		<updated>2025-10-09T06:26:31Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* install Mariadb and set up tables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Dirty and quick (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
&lt;br /&gt;
USERS&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
There are more fields than in usual tutorials you can retrieve online. &lt;br /&gt;
*enabled: user can receive emails&lt;br /&gt;
*imap_enabled: user can retieve email with IMAPs protocol&lt;br /&gt;
*smtp_enabled: user can use smtp service to send email from a remote client&lt;br /&gt;
*smtp_username: to authenticate SMTP, can be different from the email address&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
DOMAINS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
ALIAS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, smtp_username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND imap_enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can configure different users for SMTP and IMAP or enable/disable SMTPP for IMAP users.&lt;br /&gt;
The table structure created above have fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting smtp_enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND smtp_enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=215</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=215"/>
		<updated>2025-10-09T06:21:34Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* SMTP auth with cyrus-sasl */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Dirty and quick (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
&lt;br /&gt;
USERS&lt;br /&gt;
&lt;br /&gt;
CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
DOMAINS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
ALIAS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND imap_enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can configure different users for SMTP and IMAP or enable/disable SMTPP for IMAP users.&lt;br /&gt;
The table structure created above have fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting smtp_enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND smtp_enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=214</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=214"/>
		<updated>2025-10-09T06:19:56Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* SMTP auth with cyrus-sasl */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Dirty and quick (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
&lt;br /&gt;
USERS&lt;br /&gt;
&lt;br /&gt;
CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
DOMAINS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
ALIAS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND imap_enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can authenticate different users from dovecot or enable/disable active users in order to authorize SMTP. The table structure created above have 2 fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
Setting enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND smtp_enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=213</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=213"/>
		<updated>2025-10-09T06:19:29Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Dovecot IMAP */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Dirty and quick (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
&lt;br /&gt;
USERS&lt;br /&gt;
&lt;br /&gt;
CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
DOMAINS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
ALIAS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND imap_enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can authenticate different users from dovecot or enable/disable active users in order to authorize SMTP. The table structure created above have 2 fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
Setting enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=212</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=212"/>
		<updated>2025-10-09T06:18:53Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Postfix */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Dirty and quick (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
&lt;br /&gt;
USERS&lt;br /&gt;
&lt;br /&gt;
CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
DOMAINS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
ALIAS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can authenticate different users from dovecot or enable/disable active users in order to authorize SMTP. The table structure created above have 2 fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
Setting enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=211</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=211"/>
		<updated>2025-10-09T06:18:02Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Postfix */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Dirty and quick (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
&lt;br /&gt;
USERS&lt;br /&gt;
&lt;br /&gt;
CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
DOMAINS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
ALIAS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; &lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;AND enabled=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can authenticate different users from dovecot or enable/disable active users in order to authorize SMTP. The table structure created above have 2 fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
Setting enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=210</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=210"/>
		<updated>2025-10-09T06:16:48Z</updated>

		<summary type="html">&lt;p&gt;Administrator: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Dirty and quick (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
&lt;br /&gt;
USERS&lt;br /&gt;
&lt;br /&gt;
CREATE TABLE `users` (&lt;br /&gt;
  `email` varchar(200) NOT NULL,&lt;br /&gt;
  `enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `password` varchar(128) NOT NULL,&lt;br /&gt;
  `imap_enabled` int(11) DEFAULT 1,&lt;br /&gt;
  `smtp_enabled` int(11) NOT NULL DEFAULT 1,&lt;br /&gt;
  `smtp_username` varchar(45) DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`email`)&lt;br /&gt;
) ENGINE=MyISAM DEFAULT CHARSET=utf8&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
DOMAINS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
ALIAS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; &lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can authenticate different users from dovecot or enable/disable active users in order to authorize SMTP. The table structure created above have 2 fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
Setting enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=209</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=209"/>
		<updated>2025-10-08T14:06:09Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* SMTP auth with cyrus-sasl */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Dirty and quick (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
&lt;br /&gt;
USERS&lt;br /&gt;
 &lt;br /&gt;
 CREATE TABLE `users` ( `email` varchar(200) NOT NULL,&lt;br /&gt;
 `password` varchar(128) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, &lt;br /&gt;
 `username` varchar(45) DEFAULT NULL, &lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
DOMAINS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
ALIAS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; &lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can authenticate different users from dovecot or enable/disable active users in order to authorize SMTP. The table structure created above have 2 fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
Setting enabled=0 means the users cannot use SMTP auth (cannot send email from outside using this server as relay) &lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=208</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=208"/>
		<updated>2025-10-08T14:04:44Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Postfix */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Dirty and quick (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
&lt;br /&gt;
USERS&lt;br /&gt;
 &lt;br /&gt;
 CREATE TABLE `users` ( `email` varchar(200) NOT NULL,&lt;br /&gt;
 `password` varchar(128) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, &lt;br /&gt;
 `username` varchar(45) DEFAULT NULL, &lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
DOMAINS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
ALIAS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; &lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can authenticate different users from dovecot or enable/disable active users in order to authorize SMTP. The table structure created above have 2 fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=207</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=207"/>
		<updated>2025-10-08T14:04:02Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* SMTP auth with cyrus-sasl */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Dirty and quick (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
&lt;br /&gt;
USERS&lt;br /&gt;
 &lt;br /&gt;
 CREATE TABLE `users` ( `email` varchar(200) NOT NULL,&lt;br /&gt;
 `password` varchar(128) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, &lt;br /&gt;
 `username` varchar(45) DEFAULT NULL, &lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
DOMAINS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
ALIAS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1 &lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039; and enabled=1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can authenticate different users from dovecot or enable/disable active users in order to authorize SMTP. The table structure created above have 2 fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND enabled=1&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=206</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=206"/>
		<updated>2025-10-08T14:03:35Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* SMTP auth with cyrus-sasl */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Dirty and quick (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
&lt;br /&gt;
USERS&lt;br /&gt;
 &lt;br /&gt;
 CREATE TABLE `users` ( `email` varchar(200) NOT NULL,&lt;br /&gt;
 `password` varchar(128) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, &lt;br /&gt;
 `username` varchar(45) DEFAULT NULL, &lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
DOMAINS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
ALIAS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1 &lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039; and enabled=1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can authenticate different users from dovecot or enable/disable active users in order to authorize SMTP. The table structure created above have 2 fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039; AND &lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=205</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=205"/>
		<updated>2025-10-08T14:01:47Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* SMTP auth with cyrus-sasl */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Dirty and quick (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
&lt;br /&gt;
USERS&lt;br /&gt;
 &lt;br /&gt;
 CREATE TABLE `users` ( `email` varchar(200) NOT NULL,&lt;br /&gt;
 `password` varchar(128) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, &lt;br /&gt;
 `username` varchar(45) DEFAULT NULL, &lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
DOMAINS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
ALIAS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1 &lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039; and enabled=1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP users.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can authenticate different users from dovecot or enable/disable active users in order to authorize SMTP. The table structure created above have 2 fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039;&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=204</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=204"/>
		<updated>2025-10-08T14:00:56Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Postfix */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Dirty and quick (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
&lt;br /&gt;
USERS&lt;br /&gt;
 &lt;br /&gt;
 CREATE TABLE `users` ( `email` varchar(200) NOT NULL,&lt;br /&gt;
 `password` varchar(128) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, &lt;br /&gt;
 `username` varchar(45) DEFAULT NULL, &lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
DOMAINS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
ALIAS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1 &lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039; and enabled=1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Enable &amp;amp; start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP send.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can authenticate different users from dovecot or enable/disable active users in order to authorize SMTP. The table structure created above have 2 fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039;&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=203</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=203"/>
		<updated>2025-10-08T13:58:17Z</updated>

		<summary type="html">&lt;p&gt;Administrator: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Dirty and quick (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
&lt;br /&gt;
USERS&lt;br /&gt;
 &lt;br /&gt;
 CREATE TABLE `users` ( `email` varchar(200) NOT NULL,&lt;br /&gt;
 `password` varchar(128) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, &lt;br /&gt;
 `username` varchar(45) DEFAULT NULL, &lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
DOMAINS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
ALIAS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1 &lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039; and enabled=1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP send.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can authenticate different users from dovecot or enable/disable active users in order to authorize SMTP. The table structure created above have 2 fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039;&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=202</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=202"/>
		<updated>2025-10-08T13:55:33Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* SMTP auth with cyrus-sasl */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Dirty and quick (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===change your SSHd config (suggested)===&lt;br /&gt;
Not a good idea SSHd listening on default 22 port&lt;br /&gt;
   semanage port -l | grep ssh&lt;br /&gt;
   semanage port -a -t ssh_port_t -p tcp 1997&lt;br /&gt;
   semanage port -l | grep ssh&lt;br /&gt;
&lt;br /&gt;
NOTE: If you have any issue with the configurations below try disabling selinx.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 vi /etc/ssh/sshd_config&lt;br /&gt;
&lt;br /&gt;
Edit SSHD port changing to the above 1997 and restart service&lt;br /&gt;
&lt;br /&gt;
 systemctl restart sshd&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
&lt;br /&gt;
USERS&lt;br /&gt;
 &lt;br /&gt;
 CREATE TABLE `users` ( `email` varchar(200) NOT NULL,&lt;br /&gt;
 `password` varchar(128) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, &lt;br /&gt;
 `username` varchar(45) DEFAULT NULL, &lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
DOMAINS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
ALIAS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1 &lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039; and enabled=1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP send.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can authenticate different users from dovecot or enable/disable active users in order to authorize SMTP. The table structure created above have 2 fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039;&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=201</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=201"/>
		<updated>2025-10-08T13:52:57Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Dovecot IMAP */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Dirty and quick (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===change your SSHd config (suggested)===&lt;br /&gt;
Not a good idea SSHd listening on default 22 port&lt;br /&gt;
   semanage port -l | grep ssh&lt;br /&gt;
   semanage port -a -t ssh_port_t -p tcp 1997&lt;br /&gt;
   semanage port -l | grep ssh&lt;br /&gt;
&lt;br /&gt;
NOTE: If you have any issue with the configurations below try disabling selinx.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 vi /etc/ssh/sshd_config&lt;br /&gt;
&lt;br /&gt;
Edit SSHD port changing to the above 1997 and restart service&lt;br /&gt;
&lt;br /&gt;
 systemctl restart sshd&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
&lt;br /&gt;
USERS&lt;br /&gt;
 &lt;br /&gt;
 CREATE TABLE `users` ( `email` varchar(200) NOT NULL,&lt;br /&gt;
 `password` varchar(128) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, &lt;br /&gt;
 `username` varchar(45) DEFAULT NULL, &lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
DOMAINS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
ALIAS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1 &lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039; and enabled=1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol. Remove pop3 if not needed. Remove submission if you wish to configure SMTP auth with a different service (see cirus-sasl section below)&lt;br /&gt;
 protocols = imap lmtp&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP send.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can use authenticate different users from dovecot or enable/disable active users in order to authorize SMTP. The table structure created above have 2 fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039;&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=200</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=200"/>
		<updated>2025-10-08T13:51:12Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* SMTP auth with cyrus-sasl */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Dirty and quick (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===change your SSHd config (suggested)===&lt;br /&gt;
Not a good idea SSHd listening on default 22 port&lt;br /&gt;
   semanage port -l | grep ssh&lt;br /&gt;
   semanage port -a -t ssh_port_t -p tcp 1997&lt;br /&gt;
   semanage port -l | grep ssh&lt;br /&gt;
&lt;br /&gt;
NOTE: If you have any issue with the configurations below try disabling selinx.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 vi /etc/ssh/sshd_config&lt;br /&gt;
&lt;br /&gt;
Edit SSHD port changing to the above 1997 and restart service&lt;br /&gt;
&lt;br /&gt;
 systemctl restart sshd&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
&lt;br /&gt;
USERS&lt;br /&gt;
 &lt;br /&gt;
 CREATE TABLE `users` ( `email` varchar(200) NOT NULL,&lt;br /&gt;
 `password` varchar(128) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, &lt;br /&gt;
 `username` varchar(45) DEFAULT NULL, &lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
DOMAINS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
ALIAS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1 &lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039; and enabled=1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol (remove pop3 if not needed)&lt;br /&gt;
 protocols = imap lmtp submission&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP send.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can use authenticate different users from dovecot or enable/disable active users in order to authorize SMTP. The table structure created above have 2 fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039;&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=199</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=199"/>
		<updated>2025-10-08T13:47:32Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Postfix */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Dirty and quick (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===change your SSHd config (suggested)===&lt;br /&gt;
Not a good idea SSHd listening on default 22 port&lt;br /&gt;
   semanage port -l | grep ssh&lt;br /&gt;
   semanage port -a -t ssh_port_t -p tcp 1997&lt;br /&gt;
   semanage port -l | grep ssh&lt;br /&gt;
&lt;br /&gt;
NOTE: If you have any issue with the configurations below try disabling selinx.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 vi /etc/ssh/sshd_config&lt;br /&gt;
&lt;br /&gt;
Edit SSHD port changing to the above 1997 and restart service&lt;br /&gt;
&lt;br /&gt;
 systemctl restart sshd&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
&lt;br /&gt;
USERS&lt;br /&gt;
 &lt;br /&gt;
 CREATE TABLE `users` ( `email` varchar(200) NOT NULL,&lt;br /&gt;
 `password` varchar(128) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, &lt;br /&gt;
 `username` varchar(45) DEFAULT NULL, &lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
DOMAINS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
ALIAS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly (replace paths of your cerificates) &lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1 &lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039; and enabled=1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol (remove pop3 if not needed)&lt;br /&gt;
 protocols = imap lmtp submission&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP send.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can use authenticate different users from dovecot or enable/disable active users in order to authorize SMTP. The table structure created above have 2 fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039;&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
!!IMPORTANT!! Disable listening dovecot listening on port 587 otherwise there will be a port conflict between dovecot and postfix.&amp;lt;/br&amp;gt;&lt;br /&gt;
edit /etc/dovecot/conf.d/10-master.conf and set  inet_listener submission to 0 or enabled = false&lt;br /&gt;
 service submission-login {&lt;br /&gt;
  inet_listener submission {&lt;br /&gt;
    port = 0&lt;br /&gt;
  }&lt;br /&gt;
 #  inet_listener submissions {&lt;br /&gt;
 #    port = 465&lt;br /&gt;
 #  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=198</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=198"/>
		<updated>2025-10-08T13:46:20Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* install Mariadb and set up tables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Dirty and quick (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===change your SSHd config (suggested)===&lt;br /&gt;
Not a good idea SSHd listening on default 22 port&lt;br /&gt;
   semanage port -l | grep ssh&lt;br /&gt;
   semanage port -a -t ssh_port_t -p tcp 1997&lt;br /&gt;
   semanage port -l | grep ssh&lt;br /&gt;
&lt;br /&gt;
NOTE: If you have any issue with the configurations below try disabling selinx.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 vi /etc/ssh/sshd_config&lt;br /&gt;
&lt;br /&gt;
Edit SSHD port changing to the above 1997 and restart service&lt;br /&gt;
&lt;br /&gt;
 systemctl restart sshd&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter mariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
&lt;br /&gt;
USERS&lt;br /&gt;
 &lt;br /&gt;
 CREATE TABLE `users` ( `email` varchar(200) NOT NULL,&lt;br /&gt;
 `password` varchar(128) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, &lt;br /&gt;
 `username` varchar(45) DEFAULT NULL, &lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
DOMAINS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
ALIAS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly&lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1 &lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039; and enabled=1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol (remove pop3 if not needed)&lt;br /&gt;
 protocols = imap lmtp submission&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP send.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can use authenticate different users from dovecot or enable/disable active users in order to authorize SMTP. The table structure created above have 2 fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039;&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
!!IMPORTANT!! Disable listening dovecot listening on port 587 otherwise there will be a port conflict between dovecot and postfix.&amp;lt;/br&amp;gt;&lt;br /&gt;
edit /etc/dovecot/conf.d/10-master.conf and set  inet_listener submission to 0 or enabled = false&lt;br /&gt;
 service submission-login {&lt;br /&gt;
  inet_listener submission {&lt;br /&gt;
    port = 0&lt;br /&gt;
  }&lt;br /&gt;
 #  inet_listener submissions {&lt;br /&gt;
 #    port = 465&lt;br /&gt;
 #  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=197</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=197"/>
		<updated>2025-10-08T13:45:18Z</updated>

		<summary type="html">&lt;p&gt;Administrator: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Dirty and quick (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===change your SSHd config (suggested)===&lt;br /&gt;
Not a good idea SSHd listening on default 22 port&lt;br /&gt;
   semanage port -l | grep ssh&lt;br /&gt;
   semanage port -a -t ssh_port_t -p tcp 1997&lt;br /&gt;
   semanage port -l | grep ssh&lt;br /&gt;
&lt;br /&gt;
NOTE: If you have any issue with the configurations below try disabling selinx.&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 vi /etc/ssh/sshd_config&lt;br /&gt;
&lt;br /&gt;
Edit SSHD port changing to the above 1997 and restart service&lt;br /&gt;
&lt;br /&gt;
 systemctl restart sshd&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter nariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
&lt;br /&gt;
USERS&lt;br /&gt;
 &lt;br /&gt;
 CREATE TABLE `users` ( `email` varchar(200) NOT NULL,&lt;br /&gt;
 `password` varchar(128) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, &lt;br /&gt;
 `username` varchar(45) DEFAULT NULL, &lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
DOMAINS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
ALIAS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly&lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1 &lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039; and enabled=1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol (remove pop3 if not needed)&lt;br /&gt;
 protocols = imap lmtp submission&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP send.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can use authenticate different users from dovecot or enable/disable active users in order to authorize SMTP. The table structure created above have 2 fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039;&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
!!IMPORTANT!! Disable listening dovecot listening on port 587 otherwise there will be a port conflict between dovecot and postfix.&amp;lt;/br&amp;gt;&lt;br /&gt;
edit /etc/dovecot/conf.d/10-master.conf and set  inet_listener submission to 0 or enabled = false&lt;br /&gt;
 service submission-login {&lt;br /&gt;
  inet_listener submission {&lt;br /&gt;
    port = 0&lt;br /&gt;
  }&lt;br /&gt;
 #  inet_listener submissions {&lt;br /&gt;
 #    port = 465&lt;br /&gt;
 #  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=196</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=196"/>
		<updated>2025-10-08T13:35:58Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* SSL certificates */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Dirty and quick (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===change your SSHd config (suggested)===&lt;br /&gt;
Not a good idea SSHd listening on default 22 port&lt;br /&gt;
   semanage port -l | grep ssh&lt;br /&gt;
   semanage port -a -t ssh_port_t -p tcp 1997&lt;br /&gt;
   semanage port -l | grep ssh&lt;br /&gt;
&lt;br /&gt;
 vi /etc/ssh/sshd_config&lt;br /&gt;
&lt;br /&gt;
Edit SSHD port changing to the above 1997 and restart service&lt;br /&gt;
&lt;br /&gt;
 systemctl restart sshd&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQN server name (server08.vettore.org in the example)&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter nariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
&lt;br /&gt;
USERS&lt;br /&gt;
 &lt;br /&gt;
 CREATE TABLE `users` ( `email` varchar(200) NOT NULL,&lt;br /&gt;
 `password` varchar(128) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, &lt;br /&gt;
 `username` varchar(45) DEFAULT NULL, &lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
DOMAINS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
ALIAS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly&lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1 &lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039; and enabled=1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol (remove pop3 if not needed)&lt;br /&gt;
 protocols = imap lmtp submission&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP send.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can use authenticate different users from dovecot or enable/disable active users in order to authorize SMTP. The table structure created above have 2 fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039;&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
!!IMPORTANT!! Disable listening dovecot listening on port 587 otherwise there will be a port conflict between dovecot and postfix.&amp;lt;/br&amp;gt;&lt;br /&gt;
edit /etc/dovecot/conf.d/10-master.conf and set  inet_listener submission to 0 or enabled = false&lt;br /&gt;
 service submission-login {&lt;br /&gt;
  inet_listener submission {&lt;br /&gt;
    port = 0&lt;br /&gt;
  }&lt;br /&gt;
 #  inet_listener submissions {&lt;br /&gt;
 #    port = 465&lt;br /&gt;
 #  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=195</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=195"/>
		<updated>2025-10-08T13:34:23Z</updated>

		<summary type="html">&lt;p&gt;Administrator: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Dirty and quick (10 minutes) very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===change your SSHd config (suggested)===&lt;br /&gt;
Not a good idea SSHd listening on default 22 port&lt;br /&gt;
   semanage port -l | grep ssh&lt;br /&gt;
   semanage port -a -t ssh_port_t -p tcp 1997&lt;br /&gt;
   semanage port -l | grep ssh&lt;br /&gt;
&lt;br /&gt;
 vi /etc/ssh/sshd_config&lt;br /&gt;
&lt;br /&gt;
Edit SSHD port changing to the above 1997 and restart service&lt;br /&gt;
&lt;br /&gt;
 systemctl restart sshd&lt;br /&gt;
&lt;br /&gt;
===SSL certificates===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQN server name&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter nariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
&lt;br /&gt;
USERS&lt;br /&gt;
 &lt;br /&gt;
 CREATE TABLE `users` ( `email` varchar(200) NOT NULL,&lt;br /&gt;
 `password` varchar(128) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, &lt;br /&gt;
 `username` varchar(45) DEFAULT NULL, &lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
DOMAINS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
ALIAS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly&lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1 &lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039; and enabled=1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol (remove pop3 if not needed)&lt;br /&gt;
 protocols = imap lmtp submission&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP send.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can use authenticate different users from dovecot or enable/disable active users in order to authorize SMTP. The table structure created above have 2 fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039;&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
!!IMPORTANT!! Disable listening dovecot listening on port 587 otherwise there will be a port conflict between dovecot and postfix.&amp;lt;/br&amp;gt;&lt;br /&gt;
edit /etc/dovecot/conf.d/10-master.conf and set  inet_listener submission to 0 or enabled = false&lt;br /&gt;
 service submission-login {&lt;br /&gt;
  inet_listener submission {&lt;br /&gt;
    port = 0&lt;br /&gt;
  }&lt;br /&gt;
 #  inet_listener submissions {&lt;br /&gt;
 #    port = 465&lt;br /&gt;
 #  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=194</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=194"/>
		<updated>2025-10-08T13:27:47Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* change your SSHd config (suggested) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===change your SSHd config (suggested)===&lt;br /&gt;
Not a good idea SSHd listening on default 22 port&lt;br /&gt;
   semanage port -l | grep ssh&lt;br /&gt;
   semanage port -a -t ssh_port_t -p tcp 1997&lt;br /&gt;
   semanage port -l | grep ssh&lt;br /&gt;
&lt;br /&gt;
 vi /etc/ssh/sshd_config&lt;br /&gt;
&lt;br /&gt;
Edit SSHD port changing to the above 1997 and restart service&lt;br /&gt;
&lt;br /&gt;
 systemctl restart sshd&lt;br /&gt;
&lt;br /&gt;
===SSL certs===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQN server name&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter nariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
&lt;br /&gt;
USERS&lt;br /&gt;
 &lt;br /&gt;
 CREATE TABLE `users` ( `email` varchar(200) NOT NULL,&lt;br /&gt;
 `password` varchar(128) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, &lt;br /&gt;
 `username` varchar(45) DEFAULT NULL, &lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
DOMAINS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
ALIAS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly&lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1 &lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039; and enabled=1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol (remove pop3 if not needed)&lt;br /&gt;
 protocols = imap lmtp submission&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP send.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can use authenticate different users from dovecot or enable/disable active users in order to authorize SMTP. The table structure created above have 2 fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039;&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
!!IMPORTANT!! Disable listening dovecot listening on port 587 otherwise there will be a port conflict between dovecot and postfix.&amp;lt;/br&amp;gt;&lt;br /&gt;
edit /etc/dovecot/conf.d/10-master.conf and set  inet_listener submission to 0 or enabled = false&lt;br /&gt;
 service submission-login {&lt;br /&gt;
  inet_listener submission {&lt;br /&gt;
    port = 0&lt;br /&gt;
  }&lt;br /&gt;
 #  inet_listener submissions {&lt;br /&gt;
 #    port = 465&lt;br /&gt;
 #  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=193</id>
		<title>Basic mailserver configuration on RHEL10</title>
		<link rel="alternate" type="text/html" href="http://10.99.0.100:8087/index.php?title=Basic_mailserver_configuration_on_RHEL10&amp;diff=193"/>
		<updated>2025-10-08T13:26:56Z</updated>

		<summary type="html">&lt;p&gt;Administrator: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Very basic configuration of mailserver with postfix, dovecot and mysql/mariadb.&amp;lt;br&amp;gt;&lt;br /&gt;
It is the update of the previous [[basic_mailserver_configuration_on_RHEL_derivates]]&lt;br /&gt;
&lt;br /&gt;
===change your SSHd config (suggested)===&lt;br /&gt;
   semanage port -l | grep ssh&lt;br /&gt;
   semanage port -a -t ssh_port_t -p tcp 1997&lt;br /&gt;
   semanage port -l | grep ssh&lt;br /&gt;
&lt;br /&gt;
 vi /etc/ssh/sshd_config&lt;br /&gt;
&lt;br /&gt;
Edit SSHD port changing to the above 1997 and restart service&lt;br /&gt;
&lt;br /&gt;
 systemctl restart sshd&lt;br /&gt;
&lt;br /&gt;
===SSL certs===&lt;br /&gt;
 dnf install epel-release&lt;br /&gt;
 dnf install certbot&lt;br /&gt;
Create cert with your FQN server name&lt;br /&gt;
 certbot certonly -d server08.vettore.org&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===install Mariadb and set up tables===&lt;br /&gt;
&lt;br /&gt;
 timedatectl set-timezone Europe/Rome&lt;br /&gt;
 dnf install mariadb&lt;br /&gt;
 dnf install mariadb-server&lt;br /&gt;
 systemctl enable mariadb --now&lt;br /&gt;
&lt;br /&gt;
Enter nariadb console and:&lt;br /&gt;
&lt;br /&gt;
 create database mailserver;&lt;br /&gt;
 use mailserver;&lt;br /&gt;
&lt;br /&gt;
USERS&lt;br /&gt;
 &lt;br /&gt;
 CREATE TABLE `users` ( `email` varchar(200) NOT NULL,&lt;br /&gt;
 `password` varchar(128) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, &lt;br /&gt;
 `username` varchar(45) DEFAULT NULL, &lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
DOMAINS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE&lt;br /&gt;
 `domains` ( `domain` varchar(200) NOT NULL,&lt;br /&gt;
 `enabled` int(11) NOT NULL DEFAULT &#039;1&#039;, PRIMARY KEY (`domain`))&lt;br /&gt;
  ENGINE=MyISAM DEFAULT CHARSET=utf8 &lt;br /&gt;
 &lt;br /&gt;
ALIAS:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE `aliases` ( `email` varchar(128) NOT NULL,&lt;br /&gt;
 `alias` varchar(255) NOT NULL,&lt;br /&gt;
 `enabled` int(11) DEFAULT &#039;1&#039;,&lt;br /&gt;
  PRIMARY KEY (`email`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
ADD a test user (enter in mariadb console):&lt;br /&gt;
 insert into users set email=&#039;paperino@274512.xyz&#039;, password=&#039;segretina412&#039;, username=&#039;paperino&#039;;&lt;br /&gt;
 insert into domains set domain=&#039;274512.xyz&#039;;&lt;br /&gt;
&lt;br /&gt;
Grant privileges:&lt;br /&gt;
 grant select on mailserver.* to postfix@localhost identified by &#039;yoursecretpassword&#039;&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
 dnf install postfix postfix-mysql&lt;br /&gt;
 groupadd -g150 vmail&lt;br /&gt;
 useradd -r  -u150 -d /var/vmail -s /sbin/nologin -g vmail vmail&lt;br /&gt;
 mkdir /var/vmail&lt;br /&gt;
 chown vmail:vmail /var/vmail&lt;br /&gt;
Edit /etc/postfix/main.cf and change/add the following line accordingly&lt;br /&gt;
 inet_protocols = all&lt;br /&gt;
 virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
 virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
 virtual_transport = dovecot&lt;br /&gt;
 smtpd_tls_cert_file = /etc/letsencrypt/live/server08.vettore.org/cert.pem&lt;br /&gt;
 smtpd_tls_key_file = /etc/letsencrypt/live/server08.vettore.org/privkey.pem&lt;br /&gt;
 smtp_tls_CApath = /etc/letsencrypt/live/ &lt;br /&gt;
 smtp_tls_CAfile = /etc/letsencrypt/live/server08.vettore.org/fullchain.pem&lt;br /&gt;
&lt;br /&gt;
Setup the connectors configured above&lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-domains.cf:&lt;br /&gt;
&lt;br /&gt;
 user = postfix&lt;br /&gt;
 password = yuorsecretpassword&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = mailserver&lt;br /&gt;
 query = SELECT 1 FROM domains WHERE domain=&#039;%s&#039; AND enabled=1 &lt;br /&gt;
&lt;br /&gt;
/etc/postfix/mysql-virtual-users.cf :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT 1 FROM users where email=&#039;%s&#039; and enabled=1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
/etc/postfix/mysql-virtual-aliases.cf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user = postfix&lt;br /&gt;
password = yoursecretpassword&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = mailserver&lt;br /&gt;
query = SELECT alias FROM aliases WHERE email=&#039;%s&#039; AND enabled=1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check your configuration with postmap (1 returned in case of success)&lt;br /&gt;
 postmap q 274512.xyz mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
 postmap -q paperino@274512.xyz mysql:/etc/postfix/mysql-virtual-users.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add this to your /etc/postfix/master.cf&lt;br /&gt;
 dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}&lt;br /&gt;
&lt;br /&gt;
Start service&lt;br /&gt;
 systemctl enable postfix --now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
===Dovecot IMAP===&lt;br /&gt;
&lt;br /&gt;
 dnf install dovecot dovecot-mysql&lt;br /&gt;
&lt;br /&gt;
edit conf.d/10-mail.conf and add/uncomment this&lt;br /&gt;
&lt;br /&gt;
 mail_location = maildir:/var/vmail/%d/%n/Maildir&lt;br /&gt;
&lt;br /&gt;
edit /etc/dovecot/conf.d/auth-sql.conf.ext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment out the first userdb section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
remove comment from the last userdb section end edit as follows:&lt;br /&gt;
&lt;br /&gt;
 userdb {&lt;br /&gt;
  driver = static&lt;br /&gt;
  args = uid=150 gid=150 home=/var/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
Rename the above file removing .ext extension&lt;br /&gt;
&lt;br /&gt;
Verify path in the passdb section of the above file. Should be /etc/dovecot/dovecot-sql.conf.ext&amp;lt;br&amp;gt;&lt;br /&gt;
You must create this file:&lt;br /&gt;
&lt;br /&gt;
 driver=mysql&lt;br /&gt;
 default_pass_scheme = PLAIN&lt;br /&gt;
 connect= host=127.0.0.1 port=3306 dbname=mailserver user=postfix password=yoursecretpassword&lt;br /&gt;
 password_query = SELECT password, email as user  FROM users where email=&#039;%u&#039; AND enabled=1&lt;br /&gt;
&lt;br /&gt;
in  conf.d/10-ssl.conf add the certifcate and key replacing with the path of the certificate created above (but not the CA)&lt;br /&gt;
&lt;br /&gt;
in dovecot.conf remove comment from protocol (remove pop3 if not needed)&lt;br /&gt;
 protocols = imap lmtp submission&lt;br /&gt;
&lt;br /&gt;
Add to the bottom:&lt;br /&gt;
&lt;br /&gt;
 mail_uid=vmail&lt;br /&gt;
 mail_gid=vmail&lt;br /&gt;
 &lt;br /&gt;
 first_valid_uid = 150&lt;br /&gt;
 last_valid_uid = 150&lt;br /&gt;
 &lt;br /&gt;
 service stats {&lt;br /&gt;
  unix_listener stats-reader {&lt;br /&gt;
    group = vmail&lt;br /&gt;
    mode = 0666&lt;br /&gt;
  }&lt;br /&gt;
   unix_listener stats-writer {&lt;br /&gt;
     group = vmail&lt;br /&gt;
     mode = 0666&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Start end enable service&lt;br /&gt;
&lt;br /&gt;
systemctl enable dovecot --now&lt;br /&gt;
&lt;br /&gt;
===SMTP auth with cyrus-sasl===&lt;br /&gt;
Not the easiest way: you can use directly dovecot to authenticate SMTP send.&amp;lt;/br&amp;gt;&lt;br /&gt;
But the advantage of cyrus-sasl is you can use authenticate different users from dovecot or enable/disable active users in order to authorize SMTP. The table structure created above have 2 fields for this purpose.&amp;lt;/br&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 dnf install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-sql&lt;br /&gt;
&lt;br /&gt;
edit  /etc/sasl2/smtpd.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pwcheck_method: auxprop&lt;br /&gt;
mech_list: PLAIN LOGIN&lt;br /&gt;
auxprop_plugin: sql&lt;br /&gt;
sql_usessl: no&lt;br /&gt;
sql_engine: mysql&lt;br /&gt;
sql_hostnames: localhost&lt;br /&gt;
sql_user: postfix&lt;br /&gt;
sql_database: mailserver&lt;br /&gt;
sql_passwd: yoursecretpassword&lt;br /&gt;
sql_select: select password from users where username = &#039;%u&#039;&lt;br /&gt;
log_level: 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uncomment the following line in /etc/postfix/masters.cf&lt;br /&gt;
 submission inet n       -       n       -       -       smtpd&lt;br /&gt;
&lt;br /&gt;
add the following to /etc/postfix/main.cf&lt;br /&gt;
 smtpd_use_tls = yes&lt;br /&gt;
 smtpd_sasl_path = smtpd&lt;br /&gt;
 smtpd_sasl_auth_enable = yes&lt;br /&gt;
 smtpd_sasl_type = cyrus&lt;br /&gt;
 smtpd_sasl_security_options = noanonymous&lt;br /&gt;
 smtpd_tls_auth_only = yes&lt;br /&gt;
&lt;br /&gt;
!!IMPORTANT!! Disable listening dovecot listening on port 587 otherwise there will be a port conflict between dovecot and postfix.&amp;lt;/br&amp;gt;&lt;br /&gt;
edit /etc/dovecot/conf.d/10-master.conf and set  inet_listener submission to 0 or enabled = false&lt;br /&gt;
 service submission-login {&lt;br /&gt;
  inet_listener submission {&lt;br /&gt;
    port = 0&lt;br /&gt;
  }&lt;br /&gt;
 #  inet_listener submissions {&lt;br /&gt;
 #    port = 465&lt;br /&gt;
 #  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
restart services and start (anable) saslauthd&lt;br /&gt;
 systemctl restart postfix&lt;br /&gt;
 systemctl restart dovecot&lt;br /&gt;
 systemctl enable saslauthd --now&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
</feed>