<\/span><\/h2>\n\n\n\nNext, let’s create a database. By default, you can log in to MySQL shell without a password.<\/p>\n\n\n\n
$ sudo mysql<\/pre>\n\n\n\nOnce logged in, let’s run these commands.<\/p>\n\n\n\n
MariaDB [(none)]> CREATE DATABASE postfixadmin; MariaDB [(none)]> GRANT ALL PRIVILEGES ON postfixadmin.* TO 'postfixadmin'@'localhost' IDENTIFIED BY 'M0d1fyth15'; MariaDB [(none)]> FLUSH PRIVILEGES; MariaDB [(none)]> \\q<\/pre>\n\n\n\n<\/span>Step 5. Install Postfix<\/span><\/h2>\n\n\n\nInstall the Postfix mail server from the Ubuntu default repository with this command:<\/p>\n\n\n\n
$ sudo apt install postfix-mysql<\/pre>\n\n\n\nThe mail server related data will be stored in a MySQL database. Once the package postfix-mysql installation is completed we need to create several configuration files for Postfix to communicate with the database.<\/p>\n\n\n\n
$ sudo mkdir -p \/etc\/postfix\/sql<\/pre>\n\n\n\nMatch the password, database name, and database user with those you created in the earlier step.<\/p>\n\n\n\n
$ sudo nano \/etc\/postfix\/sql\/mysql_virtual_alias_maps.cf<\/pre>\n\n\n\nuser = postfixadmin password = M0d1fyth15 hosts = localhost dbname = postfixadmin query = SELECT goto FROM alias WHERE address='%s' AND active = '1'<\/pre>\n\n\n\n$ sudo nano \/etc\/postfix\/sql\/mysql_virtual_domains_maps.cf<\/pre>\n\n\n\nuser = postfixadmin password = M0d1fyth15 hosts = localhost dbname = postfixadmin query = SELECT domain FROM domain WHERE domain='%s' AND active = '1'<\/pre>\n\n\n\n$ sudo nano \/etc\/postfix\/sql\/mysql_virtual_mailbox_maps.cf<\/pre>\n\n\n\nuser = postfixadmin password = M0d1fyth15 hosts = localhost dbname = postfixadmin query = SELECT maildir FROM mailbox WHERE username='%s' AND active = '1'<\/pre>\n\n\n\n$ sudo nano \/etc\/postfix\/sql\/mysql_virtual_alias_domain_maps.cf<\/pre>\n\n\n\nuser = postfixadmin password = M0d1fyth15 hosts = localhost dbname = postfixadmin query = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = CONCAT('%u', '@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1'<\/pre>\n\n\n\n$ sudo nano \/etc\/postfix\/sql\/mysql_virtual_alias_domain_mailbox_maps.cf<\/pre>\n\n\n\nuser = postfixadmin password = M0d1fyth15 hosts = localhost dbname = postfixadmin query = SELECT maildir FROM mailbox,alias_domain WHERE alias_domain.alias_domain = '%d' and mailbox.username = CONCAT('%u', '@', alias_domain.target_domain) AND mailbox.active = 1 AND alias_domain.active='1'<\/pre>\n\n\n\n$ sudo nano \/etc\/postfix\/sql\/mysql_virtual_mailbox_limit_maps.cf<\/pre>\n\n\n\nuser = postfixadmin password = M0d1fyth15 hosts = localhost dbname = postfixadmin query = SELECT quota FROM mailbox WHERE username='%s' AND active = '1'<\/pre>\n\n\n\n$ sudo nano \/etc\/postfix\/sql\/mysql_virtual_alias_domain_catchall_maps.cf<\/pre>\n\n\n\nuser = postfixadmin password = M0d1fyth15 hosts = localhost dbname = postfixadmin query = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = CONCAT('@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1'<\/pre>\n\n\n\nNow, we can run the commands below to edit postfix’s main.cf file.<\/p>\n\n\n\n
$ sudo postconf -e \"myhostname = $(hostname -f)\"\n$ sudo postconf -e \"mydestination = localhost\"\n$ sudo postconf -e \"mynetworks = 127.0.0.0\/8\"\n$ sudo postconf -e \"inet_protocols = ipv4\"\n$ sudo postconf -e \"inet_interfaces = all\"\n$ sudo postconf -e \"smtpd_tls_cert_file = \/etc\/ssl\/certs\/ssl-cert-snakeoil.pem\"\n$ sudo postconf -e \"smtpd_tls_key_file = \/etc\/ssl\/private\/ssl-cert-snakeoil.key\"\n$ sudo postconf -e \"smtpd_use_tls = yes\"\n$ sudo postconf -e \"smtpd_tls_auth_only = yes\"\n$ sudo postconf -e \"smtpd_sasl_type = dovecot\"\n$ sudo postconf -e \"smtpd_sasl_path = private\/auth\"\n$ sudo postconf -e \"smtpd_sasl_auth_enable = yes\"\n$ sudo postconf -e \"smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination\"\n$ sudo postconf -e \"virtual_transport = lmtp:unix:private\/lmtp\"\n$ sudo postconf -e \"virtual_mailbox_domains = proxy:mysql:\/etc\/postfix\/sql\/mysql_virtual_domains_maps.cf\"\n$ sudo postconf -e \"virtual_alias_maps = proxy:mysql:\/etc\/postfix\/sql\/mysql_virtual_alias_maps.cf, proxy:mysql:\/etc\/postfix\/sql\/mysql_virtual_alias_domain_maps.cf, proxy:mysql:\/etc\/postfix\/sql\/mysql_virtual_alias_domain_catchall_maps.cf\"\n$ sudo postconf -e \"virtual_mailbox_maps = proxy:mysql:\/etc\/postfix\/sql\/mysql_virtual_mailbox_maps.cf, proxy:mysql:\/etc\/postfix\/sql\/mysql_virtual_alias_domain_mailbox_maps.cf\"<\/pre>\n\n\n\nOnce completed, we can continue and edit \/etc\/postfix\/master.cf file:<\/p>\n\n\n\n
$ sudo nano \/etc\/postfix\/master.cf<\/pre>\n\n\n\nModify or add the following lines to the file.<\/p>\n\n\n\n
smtp inet n - y - - smtpd #smtp inet n - y - 1 postscreen #smtpd pass - - y - - smtpd #dnsblog unix - - y - 0 dnsblog #tlsproxy unix - - y - 0 tlsproxy # Choose one: enable submission for loopback clients only, or for any client. #127.0.0.1:submission inet n - y - - smtpd submission inet n - y - - smtpd -o syslog_name=postfix\/submission -o smtpd_tls_security_level=encrypt -o smtpd_sasl_auth_enable=yes # -o smtpd_tls_auth_only=yes # -o local_header_rewrite_clients=static:all # -o smtpd_reject_unlisted_recipient=no # Instead of specifying complex smtpd_<xxx>_restrictions here, # specify \"smtpd_<xxx>_restrictions=$mua_<xxx>_restrictions\" # here, and specify mua_<xxx>_restrictions in main.cf (where # \"<xxx>\" is \"client\", \"helo\", \"sender\", \"relay\", or \"recipient\"). # -o smtpd_client_restrictions= # -o smtpd_helo_restrictions= # -o smtpd_sender_restrictions= # -o smtpd_relay_restrictions= # -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject -o smtpd_client_restrictions=permit_sasl_authenticated,reject -o milter_macro_daemon_name=ORIGINATING<\/pre>\n\n\n\n<\/span>Step 6. Install Dovecot<\/span><\/h2>\n\n\n\nRun this command to install Dovecot.<\/p>\n\n\n\n
$ sudo apt install dovecot-mysql dovecot-imapd dovecot-pop3d<\/pre>\n\n\n\nOnce Dovecot is installed, we can proceed with the following steps and edit some configuration files.<\/p>\n\n\n\n
Open the \/etc\/dovecot\/conf.d\/10-auth.conf file<\/p>\n\n\n\n
$ sudo nano \/etc\/dovecot\/conf.d\/10-auth.conf<\/pre>\n\n\n\nThen, find this line<\/p>\n\n\n\n
auth_mechanisms = plain<\/pre>\n\n\n\nand replace the line with this one:<\/p>\n\n\n\n
auth_mechanisms = plain login<\/pre>\n\n\n\nThen, we need to comment !include auth-system.conf.ext and uncomment the line !include auth-sql.conf.ext<\/p>\n\n\n\n
It should look like this:<\/p>\n\n\n\n
#!include auth-system.conf.ext !include auth-sql.conf.ext<\/pre>\n\n\n\n<\/p>\n\n\n\n
Still in the 10-auth.conf file, we include auth-sql.conf.ext. So, let’s edit the file so it gets executed.<\/p>\n\n\n\n
$ sudo nano \/etc\/dovecot\/dovecot-sql.conf.ext<\/pre>\n\n\n\nInsert the following lines into the file:<\/p>\n\n\n\n
driver = mysql connect = host=localhost dbname=postfixadmin user=postfixadmin password=M0d1fyth15 default_pass_scheme = BLF-CRYPT password_query = SELECT username as user, password, '\/var\/vmail\/%d\/%n' as userdb_home, 'maildir:\/var\/vmail\/%d\/%n' as userdb_mail, 150 as userdb_uid, 8 as userdb_gid FROM mailbox WHERE username = '%u' AND active = '1' user_query = SELECT '\/var\/vmail\/%d\/%u' as home, 'maildir:\/var\/vmail\/%d\/%u' as mail, 150 AS uid, 8 AS gid, concat('dirsize:storage=', quota) AS quota FROM mailbox WHERE username = '%u' AND active = '1'<\/pre>\n\n\n\nThe lines above contain the database credentials. Make sure they match the ones you created in the previous step. Save the file and exit<\/p>\n\n\n\n
Next, open the \/etc\/dovecot\/conf.d\/10-mail.conf file and change the following values:<\/p>\n\n\n\n
$ sudo nano \/etc\/dovecot\/conf.d\/10-mail.conf<\/pre>\n\n\n\nmail_location = maildir:\/var\/vmail\/%d\/%n mail_uid = vmail mail_gid = mail mail_privileged_group = mail first_valid_uid = 150 last_valid_uid = 150<\/pre>\n\n\n\nSave the file, then exit. Now, let’s proceed with editing other dovecot configuration files.<\/p>\n\n\n\n
$ sudo nano \/etc\/dovecot\/conf.d\/10-master.conf<\/pre>\n\n\n\nThere are several changes you need to make in this file.<\/p>\n\n\n\n
Find the service lmtp section and change it to the following:<\/p>\n\n\n\n
service lmtp { unix_listener \/var\/spool\/postfix\/private\/lmtp { mode = 0600 user = postfix group = postfix } }<\/pre>\n\n\n\nFind the service auth section and change it to:<\/p>\n\n\n\n
service auth { unix_listener \/var\/spool\/postfix\/private\/auth { mode = 0666 user = postfix group = postfix } unix_listener auth-userdb { mode = 0600 user = vmail } user = dovecot }<\/pre>\n\n\n\n<\/p>\n\n\n\n
Change the service auth-worker section to the following:<\/p>\n\n\n\n
service auth-worker { user = vmail }<\/pre>\n\n\n\nDo not forget to save the file and then exit. And now, it is time to correct the permissions.<\/p>\n\n\n\n
$ sudo chown -R vmail:dovecot \/etc\/dovecot $ sudo chmod -R o-rwx \/etc\/dovecot<\/pre>\n\n\n\n<\/span>Step 7. Install PostfixAdmin<\/span><\/h2>\n\n\n\nIn this step, we will download PostfixAdmin from Github and store it in the \/opt directory.<\/p>\n\n\n\n
$ sudo cd \/opt $ sudo git clone https:\/\/github.com\/postfixadmin\/postfixadmin.git $ sudo cd \/opt\/postfixadmin $ sudo bash install.sh<\/pre>\n\n\n\nLet’s correct the permission.<\/p>\n\n\n\n
$ sudo chown -R www-data: \/opt\/postfixadmin<\/pre>\n\n\n\nAdd \/etc\/apache2\/conf-enabled\/postfixadmin.conf<\/p>\n\n\n\n
$ sudo nano \/etc\/apache2\/conf-enabled\/postfixadmin.conf<\/pre>\n\n\n\nInsert these lines into that file.<\/p>\n\n\n\n
Alias \/postfixadmin \/opt\/postfixadmin\/public <Directory \"\/opt\/postfixadmin\/public\"> AllowOverride All Options +FollowSymLinks Require all granted <\/Directory><\/pre>\n\n\n\nThen, we need to reload Apache.<\/p>\n\n\n\n
$ sudo systemctl reload apache2<\/pre>\n\n\n\nNext, let’s create config.local.php <\/p>\n\n\n\n
$ sudo nano \/opt\/postfixadmin\/config.local.php<\/pre>\n\n\n\nand insert the following lines<\/p>\n\n\n\n
<?php $CONF['database_type'] = 'mysqli'; $CONF['database_host'] = 'localhost'; $CONF['database_user'] = 'postfixadmin'; $CONF['database_password'] = 'M0d1fyth15'; $CONF['database_name'] = 'postfixadmin'; $CONF['configured'] = true; ?><\/pre>\n\n\n\nSave the file, then exit from the editor.<\/p>\n\n\n\n
Go to http:\/\/YOUR_IP_ADDRESS\/postfixadmin\/setup.php and create a setup password. If you already have a website on your server, you can also access postfixadmin at http:\/\/yourdomain.com\/postfixadmin\/setup.php<\/p>\n\n\n\n <\/figure>\n\n\n\nType your setup password twice and click on Generate setup_password hash button.<\/p>\n\n\n\n
You will see a line containing a setup password, and you need to copy it to config.local.php, something like:<\/p>\n\n\n\n
$CONF['setup_password'] = '$2y$10$YpUXiIQAP47pudUDz0n3leljN2ap5xBq\/O1ntFmgAtU0WArEXy84y';<\/pre>\n\n\n\nAfter adding the line to config.local.php file, you can refresh the page to log in and create a superadmin.<\/p>\n\n\n\n <\/figure>\n\n\n\nScroll down to create a superadmin account. The setup password you created earlier is required to create a superadmin. In the admin field, it should be filled with an email address, it should look like this:<\/p>\n\n\n\nScreenshot<\/figcaption><\/figure>\n\n\n\nNow that a superadmin has been created, you can use the credentials to log in to http:\/\/192.168.53.5\/postfixadmin\/login.php and add domains, email address, etc.<\/p>\n\n\n\n <\/figure>\n\n\n\n<\/span>Step 8. Install Webmail<\/span><\/h2>\n\n\n\nAt this point, your server can send emails. To receive emails, make sure your domain’s DNS MX record points to this server. You can use your favorite email client to send emails or use a webmail instead. Let’s install Roundcube now.<\/p>\n\n\n\n
$ sudo apt install roundcube<\/pre>\n\n\n\nNext, let’s edit rouncube configuration file at \/etc\/apache2\/conf-enabled\/roundcube.conf<\/p>\n\n\n\n
$ sudo nano \/etc\/apache2\/conf-enabled\/roundcube.conf<\/pre>\n\n\n\nUncomment this line<\/p>\n\n\n\n
# Alias \/roundcube \/var\/lib\/roundcube\/public_html<\/pre>\n\n\n\nAnd it should look like this:<\/p>\n\n\n\n
Alias \/roundcube \/var\/lib\/roundcube\/public_html<\/code><\/pre>\n\n\n\nSave the file, exit then restart apache<\/p>\n\n\n\n
$ sudo systemctl restart apache2<\/pre>\n\n\n\nThe next step is to edit another Rouncube config file, this one at \/etc\/roundcube\/config.inc.php<\/p>\n\n\n\n
$ sudo nano \/etc\/roundcube\/config.inc.php<\/pre>\n\n\n\nFind this string:<\/p>\n\n\n\n
$config['smtp_host'] = 'localhost:587';<\/pre>\n\n\n\nand replace it with this one:<\/p>\n\n\n\n
$config['smtp_host'] = 'tls:\/\/%n:587';<\/pre>\n\n\n\n<\/span>You successfully installed an Email Server on Ubuntu 24.04<\/span><\/h2>\n\n\n\nYou can now navigate to your http:\/\/YOUR_SERVER_IP_ADDRESS\/roundcube and log in using the credentials you created in the previous step. Once logged in, you can try to send an email.<\/p>\n\n\n\n
Of course, you don\u2019t have to install and configure an email server on Ubuntu 24.04 server if you have a server with us, in which case you can simply ask our expert Linux hosting admins to set all of this up for you, quickly and easily. They are available 24\u00d77 and will respond to your request immediately. Our admins will also help you with more complex mail server installation, like using OpenDKIM, SPF, and DMARC.<\/p>\n\n\n\n
PS. If you liked this post, please share it with your friends on social networks or simply leave a comment down in the comments section. Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"
In this guide, we will demonstrate how to install and configure a mail server on Ubuntu 24.04, as large and … <\/p>\n
Read More<\/a><\/p>\n","protected":false},"author":4,"featured_media":48407,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1706,1698],"tags":[1603,2144,177,59,2143],"yoast_head":"\nHow to Install and Configure an Email Server on Ubuntu 24.04 - RoseHosting<\/title>\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\t \n\t \n\t \n \n \n \n \n \n\t \n\t \n\t \n