In this blog, you will learn how to set up a mail server on EC2. We have attached screenshots for each and every step so that you don’t face any issues. Let’s begin the Installation Process.
Install Postfix
Postfix is a mail transfer agent (MTA) which is the responsible software for delivering & receiving emails, it’s essential in order to create a complete mail server.
apt install postfix

On Congiguration Link select Internet Link
Type | Description |
No configuration | Should be chosen to leave the current configuration unchanged. |
Internet site | Mail is sent and received directly using SMTP. |
Internet with smarthost | Mail is received directly using SMTP or by running a utility such as fetchmail. Outgoing mail is sent using a smart host. |
Satellite system | All mail is sent to another machine, called a ‘smarthost’, for delivery. |
Local only | The only delivered mail is the mail for local users. There is no network |
2. Give System mail Server name

3. Now in order to check postfix is running or not
systemctl status postfix

Install mailutils
The Mailutils movemail is a full-fledged mail retrieval agent which can easily be used to fetch mail from remote servers.
apt install mailutils
By default, all of your emails are in one big file. There will be a different directories for each type of email such as Drafts, Templates, Trash, Sent, Inbox. For configuring this
postconf "home_mailbox_mailbox = Maildir/" postconf -n
postconf -n will show all setting of mailbox

After Setting configuration reload and check status if is is running or not
systemctl reload postfix systemctl status postfix

Install Dovecot
Dovecot is a Mail Delivery Agent, written with security primarily in mind. It supports the major mailbox formats: mbox or Maildir. This section explains how to set it up as an IMAP or POP3 server.
apt install dovecot-imapd dovecot-pop3d dovecot-core

Now in order to check whther it is running or not
systemctl status dovecot

Inorder to setup mail box we need to modify 10-mail.conf
present in /etc/dovecot/conf.d/
. Uncomment mail_location = maildir:~/Maildir
and comment mail_location = mbox:~/mail:INBOX=/var/mail/%u

Now inorder to check if it is configured or not then run doveconf -n
. You will see mail_location = maildir:~/Maildir
then it is perfectly configured.

Now to setup folder such as Drafts, Sent, Trash, Templates
cd /etc/skel/ mkdir -p Maildir/.Drafts Maildir/.Drafts/cur Maildir/.Drafts/new Maildir/.Drafts/tmp mkdir -p Maildir/.Sent Maildir/.Sent/cur Maildir/.Sent/new Maildir/.Sent/tmp mkdir -p Maildir/.Trash Maildir/.Trash/cur Maildir/.Trash/new Maildir/.Trash/tmp mkdir -p Maildir/.Templates Maildir/.Templates/cur Maildir/.Templates/new Maildir/.Templates/tmp mkdir Maildir/cur Maildir/new Maildir/tmp chmod 700 -R Maildir/

Now you need to add user
adduser --gecos "" <User Name>

Install mutt
Mutt is a powerful command line email client. It supports both mbox and Maildir formats. The protocols supported include POP3 and IMAP.
apt install mutt
Change Hostname according to you. I have set hostname to infohubblog
sudo nano /etc/hostname sudo nano /etc/hosts sudo reboot
In order to allow mail send vi /etc/dovecot/dovecot.conf
add following line
protocols = imap imaps pop3 pop3s
Now go to Each User and configure vi .muttrc
. By Default this file is not there so you need to create yourself.
set imap_user = saurabh set imap_pass = qwerty set folder = "imaps://infohubblog" # change to hostname set spoolfile = "+INBOX" set record = "+Sent" set postponed = "+Drafts" set trash = "+Trash" mailboxes INBOX unset imap_passive set timeout=1 set sort=reverse-date
That’s all. Mail Setup is done. Now you can try sending Email. To : [email protected]

BONUS : GMAIL CONFIGURATION using mutt
Now go to Each User and configure vi .muttrc
set my_address = [email protected] set smtp_pass = [email protected] set imap_user = $my_address set imap_pass = $smtp_pass set smtp_url = smtps://[email protected]:465/ set folder = imaps://imap.gmail.com/ set postpones = Drafts unset record # Gmail does this automatically set spoolfile = +INBOX mailboxes +INBOX set from = $my_address alternates $my_address set move = no set imap_keepalive = 900 set message_cachedir = ~/.cache/mutt set header_cache = $message_cachedir
Allow Less Secure APP : https://myaccount.google.com/u/5/lesssecureapps?gar=1&pli=1&rapt=AEjHL4MfMx6Sqr5JDXXO51bdNguiA2AmleKcWIGFEIBz73hYUDkvdqWkW-jwZa_Hv5ron9yW47L2EmAcFCe7vX7L2vZdxGOB_w
https://accounts.google.com/DisplayUnlockCaptcha

If you faced any issues on “How to Set up a Mail Server on EC2” then you are free to point issues in the Comment Section. If you like our Blog the Please subscribe to our newsletter for an upcoming blog.
You can even look into our Linux Blog – Linux Networking Command, LvExtend Command, Linux Terminal Command , GroupMod Command
Be the first to comment on "How to Set up a Mail Server on EC2 | Ubuntu 20.04"