I ran into a similar issue here, whenever I ran the "deliver" process as a user to deliver mail into IMAP folders (invoked from getmail). "deliver" delivered the mail but then produces the error about writing statistics, so getmail correctly concluded that the process errored.
I don't want to make statistics-writing available to all users. I don't actually care about the statistics. So I figured out how to disable statistics. I found this commit in the changelog: 2017-12-22 13:27:48 +0200 Timo Sirainen <timo.sirai...@dovecot.fi> (aa572aa74) lib-master: Hide connect(stats-writer) errors when running via CLI Only hide errors that occur if the stats process isn't running, i.e. when socket isn't found or there's no listener. This way e.g. permission errors are still logged, which points to a wrong configuration. So if the stats sockets don't exist at *all*, deliver won't complain. To disable those stats sockets, add the following configuration to a file in /etc/dovecot/conf.d/ : service stats { unix_listener stats-reader { mode = 0 } unix_listener stats-writer { mode = 0 } } service old-stats { fifo_listener old-stats-mail { mode = 0 } fifo_listener old-stats-user { mode = 0 } unix_listener old-stats { mode = 0 } } (Per https://wiki2.dovecot.org/Services , setting mode to 0 disables the socket entirely.) Then restart dovecot, and then delete /run/dovecot/stats-* and /run/dovecot/old-stats-*. You can then run deliver without errors. Hope that helps.