How to install mail server in ubuntu 14.04
Installing a mail server in Ubuntu 14.04 involves several steps. Here's a step-by-step guide to help you set up a basic mail server using Postfix, Dovecot, and MySQL:
Step 1: Install necessary packages
Open a terminal and run the following command to install the required packages:
sudo apt-get update
sudo apt-get install postfix dovecot-imapd dovecot-pop3d mysql-server
Step 2: Configure Postfix
Postfix is the mail transfer agent (MTA) that will handle email delivery. Edit the Postfix configuration file:
sudo nano /etc/postfix/main.cf
Add the following lines to the end of the file:
mydestination = localhost
myhostname = mail.example.com
myorigin = /etc/mailname
Replace example.com
with your domain name.
Step 3: Configure Dovecot
Dovecot is the IMAP and POP3 server that will handle email retrieval. 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
MySQL will store the email accounts and passwords. Create a new database and user:
sudo mysql -u root -p
Create a new database:
CREATE DATABASE mail;
Create a new user and grant privileges:
CREATE USER 'mailuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON mail.* TO 'mailuser'@'localhost';
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:
user = mailuser
password = password
hosts = localhost
dbname = mail
Step 6: Restart services
Restart the Postfix and Dovecot services:
sudo service postfix restart
sudo service dovecot restart
Step 7: Test the mail server
Use the following command to test the mail server:
sudo telnet localhost 25
This should connect you to the Postfix server. You can then send an email using the mail
command:
echo "Subject: Test email" | mail -s "Test email" [email protected]
Replace [email protected]
with the email address you want to send the email to.
Step 8: Configure DNS
You'll need to configure your DNS settings to point to your mail server. You'll need to create a MX record that points to your mail server's IP address.
That's it! You now have a basic mail server set up in Ubuntu 14.04. You can use the mail
command to send and receive emails, and you can use a mail client like Thunderbird or Evolution to access your email accounts.