0% found this document useful (0 votes)
0 views

Email Server on a Linux

This document provides a comprehensive tutorial on configuring an email server using Linux/Ubuntu, specifically utilizing open-source technologies such as Postfix, Dovecot, Apache, MySQL, and Roundcube. It outlines the prerequisites, installation steps, and configuration details necessary to set up a fully functional email server that allows for complete control over email management without third-party limitations. By following the steps, users will be able to create email accounts, manage emails via a web interface, and ensure secure email transmission.

Uploaded by

Ayubu Zuberi
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Email Server on a Linux

This document provides a comprehensive tutorial on configuring an email server using Linux/Ubuntu, specifically utilizing open-source technologies such as Postfix, Dovecot, Apache, MySQL, and Roundcube. It outlines the prerequisites, installation steps, and configuration details necessary to set up a fully functional email server that allows for complete control over email management without third-party limitations. By following the steps, users will be able to create email accounts, manage emails via a web interface, and ensure secure email transmission.

Uploaded by

Ayubu Zuberi
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 24

EMAIL SERVER ON

A LINUX/UBUNTU
Prepared by LukuwiNET
Introduction
• Today, I will demonstrate how to configure an email server for your company, allowing
you to have your own official email address rather than using services like Gmail,
Yahoo, or Outlook. This setup will grant you full control over your email system,
without limitations on the size, bandwidth, or number of users.
• We will be using open-source technologies such as:
• - Postfix (for sending emails),
• - Dovecot(for retrieving emails),
• - Apache(as a web server),
• - MySQL (for the database),
• - Roundcube(as the webmail client),
• - Ubuntu(as the operating system).
Introduction…….
• By the end of this tutorial, you will have a fully functional
email server, which can handle both incoming and
outgoing emails with no third-party limitations. You’ll also
be able to manage emails via the web interface using
Roundcube.
Prerequisites

• Ubuntu Server: This tutorial uses Ubuntu 20.04 LTS, but the steps will work with
newer versions as well.
• Static IP Address: For your email server to be reachable on the web, you need a
public static IP address.
• Domain Name: It’s highly recommended to have a domain name to make your
email server professional (e.g., yourcompany.com).
• DNS Configuration: You’ll need to configure DNS records for your domain. This
includes an MX Record pointing to your mail server, and A Record for your
domain’s IP address.
• Basic Linux Knowledge: Familiarity with the command line, and installing and
configuring packages.
Step 1: Update Your Server and Install Required
Packages

The first step in setting up your email server is to ensure your server is
up-to-date and that you have the necessary packages installed.
1 Update and Upgrade Your System:
Before installing any packages, it’s always a good idea to update the
system:
• sudo apt update
• sudo apt upgrade
This will ensure all your software packages are current and any security
patches have been applied.
Step 1: Update Your Server and
Install Required Packages……..
2 Install Required Packages:
We need Apache (web server), MySQL (database), PHP (to
run Roundcube), and other PHP extensions required by
Roundcube. Run the following command to install
everything:
Command:
sudo apt install apache2 mysql-server php php-mysql php-
imap php-mbstring php-xml php-zip php-json libapache2-
mod-php
Step 1: Update Your Server and
Install Required Packages……..
Explanation:
Apache2: Our web server, used to host the Roundcube webmail interface.
MySQL: Used for storing email data, like users, emails, and Roundcube’s
settings.
PHP: A scripting language required for Roundcube’s web interface to
function.
PHP Extensions: These are additional features PHP needs to
communicate with the database and handle email-specific functions (like
IMAP for retrieving mail).
Step 2: Install and Configure Postfix (Mail Transfer
Agent)

Postfix is the software that will handle the sending and receiving of
emails. It is a widely used Mail Transfer Agent (MTA), known for its
performance and ease of configuration.
1 Install Postfix:
sudo apt install postfix
2 Configuring Postfix:
Choose "Internet Site" when asked for the mail server type.
For the system mail name, use your public IP address (or domain name
if you have one, e.g., mail.domain.com
Step 2: Install and Configure Postfix
(Mail Transfer Agent)…….
Postfix Configuration Details:
Once installed, you need to make some additional changes
to the Postfix configuration file. This file is where you define
how Postfix behaves when sending or receiving emails.
1 Edit the Postfix configuration file:
sudo nano /etc/postfix/main.cf
Step 2: Install and Configure Postfix
(Mail Transfer Agent)…….
2 Modify the following lines:
myhostname = management
mydomain = management.com
myorigin = $mydomain
inet_interfaces = all
inet_protocols = ipv4
myhostname = management.co.tz
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated,
reject_unauth_destination
Step 2: Install and Configure Postfix
(Mail Transfer Agent)…….
Explanation:
myhostname: The name of your mail server.
mydomain: Your domain name (e.g., domain.com)
myorigin: This specifies the domain name that will appear in the
"From" address when your server sends emails.
inet_interfaces: Specifies which network interfaces Postfix listens to
for incoming mail. “ all “ means it listens on all network interfaces.
inet_protocols: Set to ipv4 to force Postfix to use IPv4 only.
Step 2: Install and Configure Postfix
(Mail Transfer Agent)…….
3 Restart Postfix to apply the changes:
sudo systemctl restart postfix
Step 3: Install and Configure Dovecot (IMAP/POP3
Server)

Dovecot is the software that will allow users to retrieve their emails using
protocols like IMAP or POP3. While Postfix handles sending emails, Dovecot
handles receiving and managing them.
1 Install Dovecot:
Install Dovecot and the required protocols:
sudo apt install dovecot-core dovecot-imapd dovecot-pop3d
2 Configure Dovecot to Use Maildir Format:
To store emails efficiently, we’ll configure Dovecot to use the Maildir format,
which stores each email as a separate file (more efficient than the older mbox
format).
Step 3: Install and Configure
Dovecot (IMAP/POP3 Server)…..
• Open the Dovecot configuration file:
sudo nano /etc/dovecot/conf.d/10-mail.conf

• Set the mail_location to:


mail_location = maildir:~/Maildir
3 Restart Dovecot:
sudo systemctl restart dovecot
Step 4: Install and Configure Roundcube

Now that Postfix and Dovecot are handling email transport and
retrieval, we need to install Roundcube, a web-based email client
that will allow you to manage your emails through a user-friendly
web interface.
1 Install Roundcube:
sudo apt install roundcube roundcube-core roundcube-mysql
2 During the installation, you’ll be asked to configure the Roundcube
database. Select "Yes" and enter the MySQL root password when
prompted.
Step 5: Configure Roundcube to Work with Postfix and
Dovecot

1 Edit Roundcube's configuration file:


Open the Roundcube configuration file:
sudo nano /etc/roundcube/config.inc.php
2 Set the following configuration parameters**:
$config['default_host'] = 'localhost'; // IMAP Server
$config['default_port'] = 143; // IMAP Port

$config['smtp_server'] = 'localhost'; // SMTP Server (Postfix)


$config['smtp_port'] = 25; // SMTP Port

$config['smtp_port'] = 25; // Default SMTP port


$config['smtp_user'] = '%u'; // Use the full email as the SMTP username
$config['smtp_pass'] = '%p'; // Use the password provided by the user
$config['mail_domain'] = 'management.co.tz'; // Set the mail domain
$config['smtp_auth_type'] = 'LOGIN'; // Enable SMTP authentication
Step 5: Configure Roundcube to
Work with Postfix and Dovecot……
• Explanation:
default_host: This is the IMAP server that Roundcube will
connect to in order to retrieve emails (Dovecot in this case).
default_port: IMAP typically runs on port 143 (for unencrypted
traffic) or 993 (for SSL).
smtp_server: Specifies the SMTP server to be used for
sending emails (Postfix).
smtp_port: SMTP typically runs on port 25.
Step 6: Create Email Accounts

You will need to create system users for each person who will
have an email account. These users will have a corresponding
email address on your domain (e.g. [email protected])
1 Create system users:
sudo adduser user1
sudo adduser user2
Each of these commands will create a new user (with a home
directory), which can be used for email accounts.
Step 6: Create Email Accounts…..
2 Create Maildir directories for the users:
sudo mkdir -p /home/user1/Maildir
sudo mkdir -p /home/user2/Maildir
sudo chown -R user1:user1 /home/user1/Maildir
sudo chown -R user2:user2 /home/user2/Maildir
sudo chmod -R 700 /home/user1/Maildir
sudo chmod -R 700 /home/user2/Maildir
Step 7: Configure Apache to Serve Roundcube

For Roundcube to be accessible via a web browser, we need to make it


available through Apache.
1. Create a symlink to Roundcube in the web root:
sudo ln -s /usr/share/roundcube /var/www/html/roundcube
2 Enable the Roundcube Apache configuration:
sudo a2enconf roundcube
sudo systemctl reload apache2
3 uncomment these lines, firstly open this file
sudo gedit /etc/dovecot/conf.d/10-master.conf
Step 7: Configure Apache to Serve Roundcube
……

then uncomment
service pop3-login {
inet_listener pop3 {
port = 110
}
inet_listener pop3s {
port = 995
ssl = yes
}
}
Step 7: Configure Apache to Serve Roundcube
…..

service imap-login {
inet_listener imap {
port = 143
}
inet_listener imaps {
port = 993
ssl = yes
}
Step 7: Configure Apache to Serve Roundcube
…..

4 This will auto-complete addresses without a domain.


sudo gedit /etc/roundcube/config.inc.php

then add these lines


$config['mail_domain'] = '10.0.2.15';
$config['validate_email'] = false;
5 restart services

sudo systemctl restart dovecot


sudo systemctl restart apache2
sudo systemctl restart postfix
access Roundcube at
http://10.0.2.15/roundcube
Log in as user1 and send an email to user2.
Log in as user2 and send an email to user3.
Log in as user3 and send an email to user4.
Log in as user4 and send an email to user1.

You might also like