Amazon Web Services - AWS EC2 - Ubuntu 14.04
Dovecot IMAP and POP3 server
Dovecot is IMAP and POP3 mail server. It is used for communication between server's mailbox and email client.
1. Installation and starting Dovecot mail server
# apt-get install dovecot-core
# apt-get install dovecot-pop3d dovecot-imapd
- This installs POP3 and IMAP protocols.
- without this it will not be possible to connect with telnet or email client via POP3 or IMAP protocols
# dovecot --version
2.2.9
2. Starting
# service dovecot start | restart | stop
# service dovecot status
dovecot start/running, process 20199
3. Configuration directory /etc/dovecot/
All config files are located in /etc/dovecot/conf.d/ and are included (joined) by !include conf.d/*.conf in /etc/dovecot/dovecot.conf .
This is a list of changes you should do in those files. Replace red with green!
# vim 10-mail.conf
# %u - username
# %n - user part in user@domain, same as %u if there's no domain
# %d - domain part in user@domain, empty if there's no domain
# %h - home directory
#mail_location = mbox:~/mail:INBOX=/var/mail/%u
mail_location = maildir:/var/vmail/%d/%n
mail_access_groups = vmail
first_valid_uid = 2222
first_valid_gid = 2222
# vim 10-auth.conf --decides which authentication will be used
disable_plaintext_auth = no
auth_mechanisms = plain login
#!include auth-system.conf.ext
#!include auth-sql.conf.ext
#!include auth-ldap.conf.ext
!include auth-passwdfile.conf.ext
#!include auth-checkpassword.conf.ext
#!include auth-vpopmail.conf.ext
#!include auth-static.conf.ext
# vim auth-passwdfile.conf.ext - config for passwd file
passdb {
driver = passwd-file
#args = scheme=CRYPT username_format=%u /etc/dovecot/users
args = scheme=SHA1 /etc/dovecot/passwd
}
userdb {
#driver = passwd-file
#args = username_format=%u /etc/dovecot/users
driver = static
args = uid=2222 gid=2222 home=/var/vmail/%d/%n allow_all_users=yes
# Default fields that can be overridden by passwd-file
#default_fields = quota_rule=*:storage=1G
# Override fields from passwd-file
#override_fields = home=/home/virtual/%u
}
# vim 10-master.conf
default_login_user = vmail
service auth {
unix_listener /var/spool/postfix/private/auth {
mode = 0666
user = postfix
group = postfix
}
}
# vim 10-logging.conf -enable during debugging, after that comment lines
log_path = /var/log/dovecot-err.log
info_log_path = /var/log/dovecot-info.log
debug_log_path = /var/log/dovecot-debug.log
auth_debug = yes
auth_debug_passwords = yes
mail_debug = yes
log_timestamp = "%b %d %H:%M:%S "
Final results when run # doveconf -n should be:
# 2.2.9: /etc/dovecot/dovecot.conf
# OS: Linux 3.13.0-48-generic x86_64 Ubuntu 14.04.2 LTS ext4
auth_debug_passwords = yes
auth_mechanisms = plain login
debug_log_path = /var/log/dovecot-debug.log
default_login_user = vmail
disable_plaintext_auth = no
first_valid_gid = 2222
first_valid_uid = 2222
info_log_path = /var/log/dovecot-info.log
log_path = /var/log/dovecot-err.log
mail_access_groups = vmail
mail_debug = yes
mail_location = maildir:/var/vmail/%d/%n
namespace inbox {
inbox = yes
location =
mailbox Drafts {
special_use = \Drafts
}
mailbox Junk {
special_use = \Junk
}
mailbox Sent {
special_use = \Sent
}
mailbox "Sent Messages" {
special_use = \Sent
}
mailbox Trash {
special_use = \Trash
}
prefix =
}
passdb {
args = scheme=SHA /etc/dovecot/passwd
driver = passwd-file
}
protocols = " imap pop3"
service auth {
unix_listener /var/spool/postfix/private/auth {
group = postfix
mode = 0666
user = postfix
}
}
ssl_cert = </etc/dovecot/dovecot.pem
ssl_key = </etc/dovecot/private/dovecot.pem
userdb {
args = uid=2222 gid=2222 home=/var/vmail/%d/%n allow_all_users=yes
driver = static
}
4. Create /etc/dovecot/passwd file
4.1 generate SHA1 password
# doveadm pw -s sha1
password: mypass
{SHA1}14KJolV1KnrLLN0jTT3uAZ38XO4=
4.2 create /etc/dovecot/passwd file
# vim /etc/dovecot/passwd
info@domain.com:{SHA1}14KJolV1KnrLLN0jTT3uAZ38XO4=
john@domain.com:{PLAIN}myPlainPAss
support@doma.net:14KJolV1KnrLLN0jTT3uAZ38XO4= -this is also SHA1 because it is default in auth-passwdfile.conf.ext
Notice: If we don't put { } then default SHA1 is taken. Default is defined in auth-passwdfile.conf.ext with scheme=SHA1 .
4.3 grant access to passwd file
# chown root: /etc/dovecot/passwd
# chmod 644 /etc/dovecot/passwd
4.4 restart dovecot
# service dovecot restart
5. TELNET
Check login with telnet from local PC or from sewrver's terminal:
# telnet mail.mikosofter.net pop3 or $ telnet mail.mikosofter.net 110 or # telnet 123.34.44.33 110
Example:
telnet: > telnet pop.example.com pop3 telnet: Trying 192.0.2.2... telnet: Connected to pop.example.com. telnet: Escape character is '^]'. server: +OK InterMail POP3 server ready. client: USER MyUsername server: +OK please send PASS command client: PASS MyPassword server: +OK MyUsername is welcome here client: LIST server: +OK 1 messages server: 1 1801 server: . client: RETR 1 server: +OK 1801 octets server: Return-Path: sender@example.com server: Received: from client.example.com ([192.0.2.1]) server: by mx1.example.com with ESMTP server: id <20040120203404.CCCC18555.mx1.example.com@client.example.com> server: for <recipient@example.com>; Tue, 20 Jan 2004 22:34:24 +0200 server: From: sender@example.com server: Subject: Test message server: To: recipient@example.com server: Message-Id: <20040120203404.CCCC18555.mx1.example.com@client.example.com> server: server: This is a test message. server: . client: DELE 1 server: +OK client: quit server: +OK MyUsername InterMail POP3 server signing off.