Dovecot

From Indie IT - Wiki
Jump to: navigation, search

Dovecot is an open source IMAP and POP3 email server for Linux/UNIX-like systems, written with security primarily in mind. Dovecot is an excellent choice for both small and large installations. It's fast, simple to set up, requires no special administration and it uses very little memory.

HOWTO: List User Mailbox Folders

doveadm mailbox list -u user@domain.com

HOWTO: Count User Mailbox Folder Messages

doveadm mailbox status -u user@domain.com messages Drafts

HOWTO: Fix: Error: auth: pam_unix(dovecot:auth): authentication failure

auth: pam_unix(dovecot:auth): check pass; user unknown
auth: pam_unix(dovecot:auth): authentication failure; 

This is because you are sending login details which the Linux PAM Authentication system cannot understand, because you are using the 'passwd' style of user@domain.com auth login.

To fix, just comment out the 'system-auth' option from the Dovecot configuration file...

sudo nano /etc/dovecot/conf.d/10-auth.conf
     #!include auth-system.conf.ext

...and restart Dovecot.

sudo service dovecot restart

HOWTO: Fix: AfterLogic WebMail Lite Autoresponder Missing

http://www.afterlogic.com/forum/forum_posts.asp?TID=4883

http://www.afterlogic.com/wiki/Use_Sieve_for_filtering_%28WebMail_Lite%29

HOWTO: Fix: Dovecot Upgrade Error: invoke-rc.d: dangling symlink

find /etc/rc* -type l -iname '*dovecot*' -exec rm -iv {} \;
sudo apt-get -f install

HOWTO: Fix: Dovecot Startup Script In Ubuntu Server

cd /etc/init.d/
sudo ln -s /lib/init/upstart-job dovecot
sudo update-rc.d dovecot defaults
sudo service dovecot start

HOWTO: Generate Encrypted Password For Users File

doveadm pw -s CRYPT

HOWTO: Secure Dovecot Using TLS Encryption

http://xmodulo.com/2014/01/secure-mail-server-using-encryption.html

Default Ports

110: pop
143: imap
995: pop3s
993: imaps

Fetchmail To MailScanner To Sendmail To Dovecot LDA To System User (+ Sieve)

Fetchmail > MailScanner > Sendmail > Procmail > Dovecot > Sieve

Just create a ~/.procmailrc file in your user's home directory...

DEFAULT=$HOME/.maildir/
LOGFILE=$HOME/procmail.log
DELIVER="/usr/libexec/dovecot/deliver"
DROPPRIVS="YES"
:0 w
| $DELIVER

...and then check the server email logs for the entries...

Jul 30 16:56:47 server1 dovecot: lda(user): msgid=<0933320008058003531@mail.domain.com>: saved mail to INBOX

dovecot: lda(sieve): sieve: msgid=<201307151456.r6FEusZI017531@mail.server.com>: sent vacation response to <me@server.com>

http://wiki2.dovecot.org/procmail

http://binblog.info/2011/11/24/dovecot-lda-behind-procmail/

Fetchmail To MailScanner To Dovecot LDA To Virtual User

To be done, after the one below!


NOTES:

The /etc/mail/virtusertable file

http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch21_:_Configuring_Linux_Mail_Servers#Using_Sendmail_to_Change_the_Sender.27s_Email_Address

Sendmail To Dovecot LDA

Local > Sendmail > Dovecot LDA > Virtual User Maildir

Following - http://wiki2.dovecot.org/LDA/Sendmail

dovecot --version

2.0.19

sendmail -d0.1

Version 8.14.4

/etc/mail $ ls

access access.db aliases aliases.db authinfo authinfo.db helpfile local-host-names mailertable mailertable.db sendmail.cf sendmail.mc sendmail.mc.orig statistics submit.cf submit.mc trusted-users virtuserdomains

/etc/mail/sendmail.mc

divert(-1)
divert(0)dnl
include(`/usr/share/sendmail-cf/m4/cf.m4')dnl
VERSIONID(`$Id: sendmail-procmail.mc,v 1.2 2004/12/07 01:59:31 g2boojum Exp $')dnl
OSTYPE(linux)dnl
DOMAIN(generic)dnl
dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1,Name=MTA')
dnl DAEMON_OPTIONS(`Port=smtp,Addr=192.168.0.207,Name=MTA')
define(`ALIAS_FILE', `/etc/mail/aliases')
define(`STATUS_FILE',`/etc/mail/statistics')
define(`SMART_HOST',`[auth.smtp.1and1.co.uk]')
FEATURE(`authinfo',`hash -o /etc/mail/authinfo.db')
FEATURE(`access_db')
FEATURE(`always_add_domain')
FEATURE(`relay_entire_domain')
FEATURE(`accept_unresolvable_domains')
dnl FEATURE(`virtusertable')
FEATURE(`mailertable')
FEATURE(`smrsh',`/usr/sbin/smrsh')
FEATURE(`local_lmtp',`/usr/sbin/mail.local')
FEATURE(`local_procmail')
FEATURE(`limited_masquerade')
FEATURE(`masquerade_envelope')
MASQUERADE_AS(`littlefield.uk.com')
MASQUERADE_DOMAIN(`vmware-gentoo-server.littlefield.uk.com')
VIRTUSER_DOMAIN_FILE(`/etc/mail/virtuserdomains')
MAILER(dovecot)
MAILER(procmail)
dnl MAILER(smtp)
MAILER(local)

/usr/share/sendmail-cf/mailer/dovecot.m4

Mdovecot, P=/usr/libexec/dovecot/dovecot-lda,
          F=DFMPhnu9,
          S=EnvFromSMTP/HdrFromSMTP,
          R=EnvToSMTP/HdrFromSMTP,
          U=vmail:vmail,
          T=DNS/RFC822/X-Unix,
          A=/usr/libexec/dovecot/dovecot-lda -d $u

/etc/mail/local-host-names

vmware-gentoo-server.littlefield.uk.com
vmware-gentoo-server
localhost.localdomain
localhost

/etc/mail/virtuserdomains

littlefield.org.uk

/etc/mail/mailertable

littlefield.org.uk dovecot:localhost

/etc/dovecot/conf.d/10-master.conf

service auth {
  unix_listener auth-userdb {
    mode = 0600
    user = vmail
    group = vmail
  }

/etc/dovecot/users

test@littlefield.org.uk:{PLAIN}password

/home/vmail/

-rw------- 1 vmail vmail  50K 2012-08-05 21:56 fetchmail.log
drwx------ 4 vmail vmail 4.0K 2012-08-05 17:30 test@littlefield.org.uk

dovecot-lda

-rwxr-xr-x 1 root root 23K 2012-08-05 15:27 /usr/libexec/dovecot/dovecot-lda

test message

echo "message" |mail -s "test" -v test@littlefield.org.uk |sed 's/^/ /'

test@littlefield.org.uk... Connecting to [127.0.0.1] via relay...
220 vmware-gentoo-server.littlefield.uk.com ESMTP Sendmail 8.14.4/8.14.4; Thu, 9 Aug 2012 17:20:19 +0100
>>> EHLO vmware-gentoo-server.littlefield.uk.com
250-vmware-gentoo-server.littlefield.uk.com Hello localhost.localdomain [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-EXPN
250-VERB
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-AUTH DIGEST-MD5 CRAM-MD5
250-DELIVERBY
250 HELP
>>> VERB
250 2.0.0 Verbose mode
>>> MAIL From:<root@vmware-gentoo-server.littlefield.uk.com> SIZE=51 AUTH=root@vmware-gentoo-server.littlefield.uk.com
250 2.1.0 <root@vmware-gentoo-server.littlefield.uk.com>... Sender ok
>>> RCPT To:<test@littlefield.org.uk>
>>> DATA
250 2.1.5 <test@littlefield.org.uk>... Recipient ok
354 Enter mail, end with "." on a line by itself
>>> .
050 <test@littlefield.org.uk>... Connecting to localhost via dovecot...
050 <test@littlefield.org.uk>... Sent
250 2.0.0 q79GKJWt004166 Message accepted for delivery
test@littlefield.org.uk... Sent (q79GKJWt004166 Message accepted for delivery)
Closing connection to [127.0.0.1]
>>> QUIT
221 2.0.0 vmware-gentoo-server.littlefield.uk.com closing connection

/var/log/mail.log

Aug  9 17:20:19 vmware-gentoo-server sendmail[4165]: q79GKJN9004165: from=root, size=51, class=0, nrcpts=1, msgid=<201208091620.q79GKJN9004165@vmware-gentoo-server.littlefield.uk.com>, relay=root@localhost
Aug  9 17:20:19 vmware-gentoo-server sm-mta[4166]: q79GKJWt004166: from=<root@vmware-gentoo-server.littlefield.uk.com>, size=406, class=0, nrcpts=1, msgid=<201208091620.q79GKJN9004165@vmware-gentoo-server.littlefield.uk.com>, proto=ESMTP, daemon=MTA, relay=localhost.localdomain [127.0.0.1]
Aug  9 17:20:19 vmware-gentoo-server sm-mta[4166]: q79GKJWt004166: to=<test@littlefield.org.uk>, ctladdr=<root@vmware-gentoo-server.littlefield.uk.com> (0/0), delay=00:00:00, xdelay=00:00:00, mailer=dovecot, pri=30406, relay=localhost, dsn=2.0.0, stat=Sent
Aug  9 17:20:19 vmware-gentoo-server sendmail[4165]: q79GKJN9004165: to=test@littlefield.org.uk, ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30051, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (q79GKJWt004166 Message accepted for delivery)

/var/log/dovecot/dovecot-info.log

Aug 09 17:20:19 lda(test@littlefield.org.uk): Info: msgid=<201208091620.q79GKJN9004165@vmware-gentoo-server.littlefield.uk.com>: saved mail to INBOX

/var/log/dovecot/dovecot-debug.log

Aug 09 17:20:19 auth: Debug: Loading modules from directory: /usr/lib64/dovecot/auth
Aug 09 17:20:19 auth: Debug: passwd-file /etc/dovecot/users: Read 4 users
Aug 09 17:20:19 auth: Debug: master in: USER 1 test@littlefield.org.uk service=lda
Aug 09 17:20:19 auth: Debug: passwd-file(test@littlefield.org.uk): lookup: user=test@littlefield.org.uk file=/etc/dovecot/users
Aug 09 17:20:19 auth: Debug: master out: USER 1 test@littlefield.org.uk uid=1000 gid=1000 home=/home/vmail/test@littlefield.org.uk

Virtual Users

http://wiki.dovecot.org/HowTo/SimpleVirtualInstall

Virtual Users + System Users

/etc/dovecot/conf.d/10-auth.conf

!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

/etc/dovecot/conf.d/10-master.conf

service auth {
  unix_listener auth-userdb {
    mode = 0666
    #user = 
    #group = 
}

/etc/dovecot/conf.d/auth-passwdfile.conf.ext

passdb {
  driver = passwd-file
  args = scheme=CRYPT username_format=%u /etc/dovecot/users
}

userdb {
  driver = passwd-file
  args = username_format=%u /etc/dovecot/users
}

/etc/dovecot/users

user@domain.com:{PLAIN}mypassword:vmail:vmail::/home/vmail/user@domain.com:

/home/vmail

drwxr-xr-x  4 vmail        vmail 4.0K 2012-09-20 17:58 vmail

total 88K
drwxr-xr-x  4 vmail vmail 4.0K 2012-09-20 17:58 .
drwxr-xr-x 72 root  root  4.0K 2012-09-14 15:52 ..
-rw-------  1 vmail vmail 1.6K 2012-09-20 18:06 .bash_history
-rw-r--r--  1 vmail vmail  127 2011-07-11 16:44 .bash_logout
-rw-r--r--  1 vmail vmail  193 2011-07-11 16:44 .bash_profile
-rw-r--r--  1 vmail vmail  606 2012-09-19 16:56 .bashrc
-rw-------  1 vmail vmail    8 2012-09-20 17:58 .fetchmail.pid
-rwx------  1 vmail vmail  524 2012-09-19 17:12 .fetchmailrc
-rw-------  1 vmail vmail   87 2012-09-20 17:12 .lesshst
drwx------  2 vmail vmail 4.0K 2011-07-07 11:20 .ssh
-rw-r--r--  1 vmail vmail  43K 2012-09-20 18:13 fetchmail.log
drwx------  3 vmail vmail 4.0K 2012-09-20 17:58 user@domain.com

Fetchmail to Dovecot Deliver LDA to Virtual Users

Internet > Fetchmail > Dovecot LDA > Virtual User Maildir

This will show you how to fetch mail from the internet and deliver it to local virtual email users. This is like taking a backup of your IMAP folder. Again, I could not find a single web page on the internet which showed this, so I am writing it down now so that someone else doesn't spend 3 hours trying to figure it out. :-(

http://llg.cubic.org/docs/imapbackup.html

This example is using IMAP and keeping the emails in the internet server, but you could use POP and delete the emails on the server.

Install Fetchmail

emerge fetchmail

Create the Virtual Mail User

useradd -c "Virtual Mail User" -d /home/vmail -U -m vmail
passwd vmail

Create the Fetchmail config file for the user 'vmail' (created for the Virtual Users above) which will go and get then deliver the emails.

cd /home/vmail/
touch .fetchmailrc
chown vmail:vmail .fetchmailrc
chmod 0700 .fetchmailrc
nano .fetchmailrc

This is the magic config file. The Dovecot documentation showed dovecot-lda -f $FROM_ENVELOPE -d $DEST_USERNAME but I could not get this variable to work, so hard coded it instead... at least, for now.

/home/vmail/.fetchmailrc
set daemon 300
set logfile /home/vmail/fetchmail.log
set no bouncemail
set postmaster vmail
poll imap.domain.co.uk protocol imap
     username "test@domain.org.uk" password "mypassword" fetchall keep
     mda "/usr/libexec/dovecot/dovecot-lda -d test@domain.org.uk"
preconnect "date >> /home/vmail/fetchmail.log"

Create the user database file. To generate encrypted passwords, use doveadm:-

doveadm pw -s CRYPT
/etc/dovecot/users
test@domain.org.uk:{PLAIN}password
user@domain.org.uk:{CRYPT}r.oySJdXZSPyE

Your logs will now show something like the following:-

/home/vmail/fetchmail.log
fetchmail: 12 messages (11 seen) for test@domain.org.uk at imap.domain.co.uk.
fetchmail: reading message test@domain.org.uk@imap.domain.co.uk:12 of 12 (1426 header octets) (10 body octets) not flushed
Sat Aug  4 20:49:16 BST 2012
/var/log/dovecot/dovecot-info.log
Aug 04 20:49:17 lda(test@domain.org.uk): Info: msgid=<501D7BF9.7020604@domain.co.uk>: saved mail to INBOX

Sieve

This facility consists of 2 parts - the ManageSieve daemon and the Sieve plugins + scripts.

Add the relevant USE flags and re-install the package...

echo "net-mail/dovecot maildir managesieve sieve" >> /etc/portage/package.use
emerge -q dovecot

Uncomment the config file line to enable the ManageSieve daemon and port...

nano /etc/dovecot/conf.d/20-managesieve.conf
protocols = $protocols sieve
service managesieve-login {
  inet_listener sieve {
    port = 4190
}
nano /etc/dovecot/conf.d/15-lda.conf
protocol lda {
   # Space separated list of plugins to load (default is global mail_plugins).
mail_plugins = sieve
}

Restart Dovecot...

/etc/init.d/dovecot restart

Check the port is open...

netstat -ntap |grep dovecot
tcp        0      0 0.0.0.0:143             0.0.0.0:*               LISTEN      32135/dovecot       
tcp        0      0 0.0.0.0:4190            0.0.0.0:*               LISTEN      32135/dovecot       

http://wiki.dovecot.org/ManageSieve/Configuration http://wiki.dovecot.org/LDA/Sieve/Dovecot

Then install the Out Of Office extension for Thunderbird below...

Vacation / Out Of Office Plugin for Mozilla Thunderbird

NEW VERSION

https://github.com/opensolutions/sieve-out-of-office

OLD VERSION

http://adullact.net/plugins/mediawiki/wiki/milimail/index.php/Out_of_Office

    Sieve Settings
      Server Name: 192.168.0.207
             Port: 4190
   Authentication: Use login from IMAP Account
        User Name: test@domain.org.uk
Secure Connection: false

Just create a ~/.procmailrc file in your user's home directory...

DEFAULT=$HOME/.maildir/
LOGFILE=$HOME/procmail.log
DELIVER="/usr/libexec/dovecot/deliver"
DROPPRIVS="YES"
:0 w
| $DELIVER

...and then check the server email logs for the entry...

dovecot: lda(sieve): sieve: msgid=<201307151456.r6FEusZI017531@mail.server.com>: sent vacation response to <me@server.com>

Or, a global /etc/procmailrc for the whole server...

# Use maildir-style mailbox in user's home directory
DEFAULT=$HOME/.maildir/
# Log actions to file
LOGFILE=$HOME/procmail.log
# Log synopsis of messages
LOGABSTRACT=all
# Be verbose
VERBOSE=no
# Pass to Dovecot for Sieve
DELIVER="/usr/libexec/dovecot/deliver"
DROPPRIVS="YES"
:0 w
| $DELIVER