A mail server on ubuntu 18.04 postfix dovecot mysql
A great combination! Here's a step-by-step guide to setting up a mail server on Ubuntu 18.04 using Postfix, Dovecot, and MySQL:
Prerequisites
- Ubuntu 18.04 LTS
- A static IP address for your server
- A domain name (e.g., example.com)
- A MySQL database server (you can use the default MySQL package in Ubuntu)
Step 1: Install required packages
Update the package list and install the required packages:
sudo apt update
sudo apt install postfix dovecot-imapd dovecot-pop3d mysql-server
Step 2: Configure Postfix
Edit the Postfix configuration file:
sudo nano /etc/postfix/main.cf
Add the following lines to the end of the file:
mydestination = example.com
myhostname = mail.example.com
myorigin = $myhostname
mynetworks = 127.0.0.0/8 [::1]/128
Replace example.com
with your domain name.
Step 3: Configure Dovecot
Edit the Dovecot configuration file:
sudo nano /etc/dovecot/dovecot.conf
Add the following lines to the end of the file:
mail_location = maildir:~/Maildir
first_valid_uid = 1000
first_valid_gid = 1000
Step 4: Configure MySQL
Create a new database and user for Postfix and Dovecot:
sudo mysql -u root -p
Create a new database:
CREATE DATABASE postfix;
Create a new user and grant privileges:
CREATE USER 'postfix'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON postfix.* TO 'postfix'@'localhost';
Replace password
with a strong password.
Step 5: Configure Postfix to use MySQL
Edit the Postfix configuration file:
sudo nano /etc/postfix/mysql.cf
Add the following lines to the end of the file:
hosts = localhost
user = postfix
password = password
dbname = postfix
query = SELECT goto FROM alias WHERE address='%s'
Replace password
with the password you created earlier.
Step 6: Restart services
Restart the Postfix and Dovecot services:
sudo service postfix restart
sudo service dovecot restart
Step 7: Test your mail server
Use a mail client like Thunderbird or Outlook to test your mail server. You can also use the telnet
command to test the SMTP server:
telnet mail.example.com 25
Replace mail.example.com
with your mail server's hostname.
Step 8: Configure DNS
Update your DNS records to point to your mail server. You'll need to create an MX record and a TXT record. The MX record should point to your mail server's hostname, and the TXT record should contain the SPF record.
That's it! You now have a working mail server on Ubuntu 18.04 using Postfix, Dovecot, and MySQL.