8. Configuring a mail server

Implementing the mail service

Mail service depends on LDAP and Unix services; if those are not installed, install them by typing:

cl-setup ldap
cl-setup unix

To install the mail service, execute:

# installing with default settings
cl-setup mail

To specify a host name of the mail other than the default, use the --host option:

# mymail.mydomain.com mail host (do not put a short name, for example: mymail)
cl-setup --host mymail.mydomain.com mail

Using the POP3 and/or IMAP protocol is specified with the --type option:

# installing the service with support for POP3 and IMAP with TLS encryption
cl-setup --type imap,pop3 mail
# installing only with support of POP3 and TLS
cl-setup --type pop3 mail

Using (or not) encryption is defined with the --crypt parameter:

# TLS will be used, and only IMAP will come by default
cl-setup --crypt tls mail 
# without encryption, and only IMAP will come by default
cl-setup --crypt none mail

If you need to specify the network protocols and encryption, then use the command with the parameters as shown below:

# without encryption, support for IMAP and POP3
cl-setup --crypt none --type imap,pop3 mail

After you run cl-setup command, configure and launch the mail service with the required set of parameters. Have a look at the open ports to verify the results:

> nmap localhost
25/tcp   open  smtp
993/tcp  open  imaps # if without TLS, port 143
995/tcp  open  pop3s # if without TLS, port 110

To prevent spam delivery, no mail directory is created for the system users, specified in /etc/mail/aliases.

If you want the users specified in /etc/mail/aliases to receive messages, execute:

mkdir /var/calculate/server-data/mail/nobody
chown nobody:nobody /var/calculate/server-data/mail/nobody
chmod 0700 /var/calculate/server-data/mail/nobody

Letters sent to the system mail users will be located in the /var/calculate/server-data/mail/nobody.

Mail accounts

A mail account contains registration data required for the user to be autheticated at login. Here, it is used to connect to the mail service or to the mail box.

A mail box is a logical container that is used to store electronic mail messages on disk and denoted by an e-mail address. The mailbox may have multiple e-mail addresses, called email address synonyms (e-mail aliases).

Manage accounts

Add an account

You can add accounts with the cl-useradd command:

cl-useradd -p -e <one or more mail alias(es), comma-separated> <account> mail

# Adding user _guest_ with e-mail guestmail@mymail.mydomain.com
cl-useradd -p -e guestmail@mymail.mydomain.com guest mail

Change the password

To change the e-mail password, use cl-passwd:

cl-passwd guest mail

Delete an account

To delete accounts, use the cl-userdel command:

cl-userdel guest mail

Mail groups

A mail group is a set of email addresses used to send newsletters to several addressees. Letters sent to the group address would be sent to all e-mail accounts belonging to this group.

Manage mail groups

Add a mail group

Adding a mail group is performed with cl-groupadd:

# add the _guestgroup_ mail group with the alternative e-mail gg@mydomain.com
cl-groupadd -e gg@mydomain.com guestgroup mail

Delete a mail group

To delete groups, use cl-groupdel:

# delete the _guestgroup_ group
cl-groupdel guestgroup mail

Add and remove account from group

Adding and removing accounts can be done in two ways:
  • with the cl-usermod command
    # add the user _guest_ to the _guesttest_ and _guestgroup_ groups
    cl-usermod -a guesttest,guestgroup guest mail
    # change the group of the user _guest_ to _guesttest_
    cl-usermod -G guesttest guest mail
  • with the cl-groupmod command
    # remove the users _guest1_ and _guest2_ from the _guesttest_ group
    cl-groupmod -d guest1,guest2 guesttest mail
    # add the users _guest1_ and _guest2_ to the _guesttest_ group
    cl-groupmod -a guest1,guest2 guesttest mail

Check the server

To check the server, you can use telnet. The server must be configured with no encryption. The final working version, for security, should use encryption.
  1. install the service
    cl-setup --type imap,pop3 --crypt none mail
  2. add the guest user
    cl-useradd -p -e guest@mymail.mydomain.org guest mail
  3. enter the password
  4. run telnet
    > telnet
  5. connect to SMTP
    > open localhost 25
    Connected to mymail.mydomain.org.
    Escape character is '^]'.
    220 mymail.mydomain.org ESMTP
    > EHLO "mymail" 
    250-SIZE 100000000
    250 DSN
    > MAIL FROM:<noname@mailer.org>
    250 2.1.0 Ok
    > RCPT TO:<guest@mymail.mydomain.org>
    250 2.1.5 Ok
    > DATA
    354 End data with <CR><LF>.<CR><LF>
    > Hello
    > .
    250 2.0.0 Ok: queued as D42932B91
    > QUIT
    221 2.0.0 Bye
    Connection closed by foreign host.
  6. now run telnet and connect to POP3
    > telnet
    > open localhost 110
    Connected to mymail.mydomain.org.
    Escape character is '^]'.
    +OK Dovecot ready.
    > USER guest
    > PASS 111
    +OK "Authentication successful" 
    > LIST
    +OK 1 messages:  "One message on server" 
    1 529
    +OK Logging out.
    Connection closed by foreign host.
Thank you!