Install and configure a simple mail server using Sendmail and Dovecot on a Fedora 20 VPS


Install and configure a simple mail server using Sendmail and Dovecot on a Fedora 20 VPS In the following article we will guide you through the steps of installing and configuring a simple mail server using Sendmail and Dovecot on a Fedora 20 Linux VPS.

What is Sendmail?

It is a general purpose email routing facility that supports many kinds of mail-transfer and delivery methods, including the Simple Mail Transfer Protocol (SMTP) used for email transport over the Internet.

What is Dovecot?

Dovecot is an open source IMAP and POP3 server for Linux/UNIX-like systems. It can work with standard mbox, Maildir, and its own native high-performance dbox formats. It is fully compatible with UW IMAP and Courier IMAP servers’ implementation of them, as well as mail clients accessing the mailboxes directly. Dovecot also includes a Mail delivery agent (called Local delivery agent LDA) with optional Sieve filtering support.

UPDATE THE SYSTEM

Before proceeding any further, make sure you are in a screen session and check if your Fedora 20 Linux VPS is fully up-to-date by running:

## screen -U -S sendmail-screen
## yum update

INSTALL AND CONFIGURE SENDMAIL

Install Sendmail MTA using the following command

## yum install sendmail sendmail-cf sendmail-doc cyrus-sasl-{lib,plain}

change to /etc/mail directory

## cd /etc/mail

edit sendmail’s sendmail.mc configuration file and add/change the following

## cp sendmail.mc{,.orig}
## vim sendmail.mc
define(`PROCMAIL_MAILER_PATH', `/usr/bin/procmail')dnl
define(`confAUTH_OPTIONS', `A')dnl
TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl

FEATURE(local_procmail)dnl

DAEMON_OPTIONS(`Port=smtp,Addr=0.0.0.0, Name=MTA')dnl
DAEMON_OPTIONS(`Port=submission, Name=MSA, M=Ea')dnl

MAILER(procmail)dnl

save and close the file and make sendmail’s configuration by running the following commands

## cd /etc/mail
## make all

restart sendmail and add it to your linux vps start-up using systemctl

## systemctl restart sendmail saslauthd
## systemctl enable sendmail saslauthd

for your convenience, below is the complete sendmail.mc configuration file:

divert(-1)dnl
include(`/usr/share/sendmail-cf/m4/cf.m4')dnl
VERSIONID(`setup for linux')dnl
OSTYPE(`linux')dnl
define(`confDEF_USER_ID', ``8:12'')dnl
define(`confTO_CONNECT', `1m')dnl
define(`confTRY_NULL_MX_LIST', `True')dnl
define(`confDONT_PROBE_INTERFACES', `True')dnl
define(`PROCMAIL_MAILER_PATH', `/usr/bin/procmail')dnl
define(`ALIAS_FILE', `/etc/aliases')dnl
define(`STATUS_FILE', `/var/log/mail/statistics')dnl
define(`UUCP_MAILER_MAX', `2000000')dnl
define(`confUSERDB_SPEC', `/etc/mail/userdb.db')dnl
define(`confPRIVACY_FLAGS', `authwarnings,novrfy,noexpn,restrictqrun')dnl
define(`confAUTH_OPTIONS', `A')dnl
TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
define(`confTO_IDENT', `0')dnl
FEATURE(`no_default_msa', `dnl')dnl
FEATURE(`smrsh', `/usr/sbin/smrsh')dnl
FEATURE(`mailertable', `hash -o /etc/mail/mailertable.db')dnl
FEATURE(`virtusertable', `hash -o /etc/mail/virtusertable.db')dnl
FEATURE(redirect)dnl
FEATURE(always_add_domain)dnl
FEATURE(use_cw_file)dnl
FEATURE(use_ct_file)dnl
FEATURE(local_procmail)dnl
FEATURE(`access_db', `hash -T<TMPF> -o /etc/mail/access.db')dnl
FEATURE(`blacklist_recipients')dnl
EXPOSED_USER(`root')dnl
DAEMON_OPTIONS(`Port=smtp,Addr=0.0.0.0, Name=MTA')dnl
DAEMON_OPTIONS(`Port=submission, Name=MSA, M=Ea')dnl
FEATURE(`accept_unresolvable_domains')dnl
LOCAL_DOMAIN(`localhost.localdomain')dnl
MAILER(smtp)dnl
MAILER(procmail)dnl

INSTALL AND CONFIGURE DOVECOT

Install dovecot using the command below

## yum install dovecot

change to dovecot’s directory in /etc/dovecot

## cd /etc/dovecot

and edit the following

## vim conf.d/10-mail.conf
...
mail_location = maildir:~/Maildir
## vim conf.d/10-ssl.conf
...
ssl = yes
## vim conf.d/10-auth.conf
...
disable_plaintext_auth = no
auth_mechanisms = plain login

next, edit dovecot’s main configuration file and add/edit the following

## vim dovecot.conf
...
protocols = imap pop3 lmtp
listen = *

start Dovecot and add it to your Fedora system’s start-up using

## systemctl restart dovecot
## systemctl enable dovecot

SET-UP PROCMAIL

Add the following to /etc/procmailrc

## vim /etc/procmailrc

DEFAULT=$HOME/Maildir/

CREATE A NEW USER

Create new user using the following command

## useradd -m test

set password for the newly created info account

## passwd test

add your mydomain.com domain name to /etc/mail/local-host-names

## echo mydomain.com >> /etc/mail/local-host-names

and create an alias for the newly created email account, by adding the following to /etc/mail/virtusertable

## vim /etc/mail/virtusertable

test@mydomain.com  test
sales@mydomain.com test

rebuild sendmail’s configuration by running the following commands

## cd /etc/mail
## make all
## systemctl restart sendmail

Of course, if you are one of our Linux VPS Hosting customers, you don’t have to do any of this, simply ask our admins, sit back and relax. Our admins will set this up for you immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

Tutorials
How to use rsync on a Linux VPS
Tutorials
Install Ruby, Sass and Compass
Tutorials
Install PHP 7 on Ubuntu 14.04
  • Cornelio

    CornelioCornelio

    Author Reply

    how setup a client with this configuracion?


    • admin

      adminadmin

      Author Reply

      You can setup your email client using the following settings:

      Incoming Server: yourdomain.com
      Incoming Protocol: IMAP
      Incoming Port: 143
      Outgoing Server: yourdomain.com
      Outgoing Port: 25 or 587


      • Cornelio

        CornelioCornelio

        Author Reply

        with pop?


        • admin

          adminadmin

          Author Reply

          Yes, you can also use POP3 if you like.


  • marcos

    marcosmarcos

    Author Reply

    how can i use that on sendblaster


    • admin

      adminadmin

      Author Reply

      More information on this you can find here.


  • Gaius Gracchus

    Great article! Out of many we reviewed, this was the only one that worked for us.

    Thanks!!!


  • Juan David

    Juan DavidJuan David

    Author Reply

    I have Centos 7 and Procmail but not found this path
    /etc/procmailrc.
    what wrong?


    • admin

      adminadmin

      Author Reply

      You may create /etc/procmailrc file if it does not exist.


  • chenqisu1

    chenqisu1chenqisu1

    Author Reply

    i had do that step by step, it send mail successful, but the mail cannot recive. any idea?


    • admin

      adminadmin

      Author Reply

      You can check the log files for errors. Thanks.


  • harris

    harrisharris

    Author Reply

    I had to read this three times because I wanted to be sure on some of your points. I agree on almost everything here, and I am impressed with how well you wrote this article.


  • George, Master of Time and Space

    After looking all over the Internet for weeks at dozens of articles, I finally found one that works! Thank you guys very much!

    One last thing, how do you get aliases to work?


    • admin

      adminadmin

      Author Reply

      Run newaliases command after changing the /etc/aliases file


  • tarounen

    tarounentarounen

    Author Reply

    after doing all the steps . i used telnet to test the system but i can getting No route found to host when i connect to port 110.

    can you help?


  • Thangapandian

    How to check my mail configuration it’s working or not.

    please give suggestion.


    • admin

      adminadmin

      Author Reply

      Please follow the tutorial instructions closely, especially the ‘CREATE A NEW USER’ section.

      In short, you need to create a new user account, add your domain name to the ‘/etc/mail/local-host-names’ file, add ‘username@mydomain.com username’ to the ‘/etc/mail/virtusertable’ file , rebuild Sendmail’s configuration and restart Sendmail for the changes to take effect.


  • Nau

    NauNau

    Author Reply

    can this one work on a centos 6??


    • admin

      adminadmin

      Author Reply

      This tutorial is written and tested on a Fedora 20 VPS, but you can also try it on your CentOS 6 VPS.