Can't seem to setup remote access to doveadmI'm using

Paul Kudla paul at
Sat Mar 18 14:13:13 UTC 2023

ok there might be other ways to do this but here is what i did for my 
django project

I had to create a listener in python


This script is designed to work on a closed network and is still rough 
around the edges but does work

needs to be run as root in the background to access the doveadm.

If you intend to access from outside then you need to secure it by 
static ip, username/password etc ???

The client side code sends an email to notify you when the script is 

Can help if you get stuck.


# cat /sbin/scripts/dovecot.listen

import os,sys
import socket
import commands
import time

from lib import *

a = onlyone ('dovecot.listen')
if a.status == 'BAD' :
         print 'Another Process Is running ....'

TCP_IP = ''
TCP_PORT = 8444
BUFFER_SIZE = 1024  # Normally 1024, but we want fast response

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((TCP_IP, TCP_PORT))

while 1 : #Process received data?
         conn, addr = s.accept() #Wait for data
         print 'Connection address:', addr
         data = conn.recv(BUFFER_SIZE)
         if not data: break
         print "received data:", data
         data = data.split (' ')
         command = data[0]
         print command

         #If CM (Create Mailbox)
         if command == 'CM' :
                 username = data[1]
                 print 'Creating Email Account : %s' % (username)
                 #Now create the mail box
                 #Now go make the email account
                 message = ''
                 for n in range (0,100) :
                         command1 = 
commands.getoutput('/usr/local/bin/doveadm mailbox create -s -u %s 
INBOX' %str(username))
                         print 'Command1 : %s' %command1
                         if 'Mailbox already exists' in command1 :
                                 message = 'BAD'
                                 conn.send( str(message) )

                         else :
                                 if message == '' :
                                         message = 'OK'
                                         message = 'SENT'

                         if "User doesn't exist" in command1 :
                         else :
                                 print 'Command1 : %s' %command1
                                 message = 'SENT'

                 if message == 'SENT' : #Create the rest
                         command2 = 
commands.getoutput('/usr/local/bin/doveadm mailbox create -s -u %s Sent' 
                         print 'Command2 : %s' %command2
                         command3 = 
commands.getoutput('/usr/local/bin/doveadm mailbox create -s -u %s 
Trash' %str(username))
                         print 'Command3 : %s' %command3
                         command4 = 
commands.getoutput('/usr/local/bin/doveadm mailbox create -s -u %s 
Drafts' %str(username))
                         print 'Command4 : %s' %command4

         if command == 'INFO' :
                 username = data[1]
                 print 'Getting Email Account Info : %s' % ( username )
                 command1 = commands.getoutput("/usr/local/bin/doveadm 
mailbox status -t all -u %s '*' " %str(username))
                 if 'Error' in command1 :
                         message = 'BAD'
                 else :
                         message = 'OK : ' + command1

                 print message
                 conn.send( str(message) )  # echo

         if command == 'DM' :
                 data = data[1]
                 data = data.split('@')
                 print 'Deleting Email Account : user/%s@%s' % ( 
str(data[0]), str(data[1]) )

                 message = 'BAD'

                 conn.send(message)  # echo
                 print message


#Go Back Around


and then in django / or outside ? :


     #Try to get info for this account
     if dontupdate == False :

       imap_test = Dovecot_Command ('INFO',self.username) #do i have 
this account ?

       if 'BAD' in imap_test.answer :
         try : #Try to Create the account, note that the db must be 
updated properly before it will work
           imap_create = Dovecot_Command ('CM',self.username)
           if 'OK' in imap_create.answer :
             send_subject = 'Email Account Created : %s' 
%(str(self.username) )

         except :
           send_subject = 'Error Account : %s' %(str(self.username) )

       else :
         send_subject = 'Email Account Updated : %s' %(self.username)

       #Send update email

       send_from = 'monitor at'
       send_files = []
       send_to = ['monitor at']
       send_text = '\n\n'+ send_subject + '\n'
#Send the warning email

     if send_settings != ''   : #Send Email Setup to this address
       servername = 'mail.%s' %domain

       send_from = 'info at'
       send_files = []
       send_to = ['%s' %send_settings,]

       send_subject = 'Email Setup Instructions for : %s %s' 

       #Assemblt the sxend text with the info


Happy Saturday !!!
Thanks - paul

Paul Kudla Internet Services <>
004-1009 Byron Street South
Whitby, Ontario - Canada
L1N 4S3

Toronto 416.642.7266
Main 1.866.411.7266
Fax 1.888.892.7266
Email paul at

On 3/17/2023 10:22 PM, dovecot-bounces at wrote:
> I’m running version 2.1.7 under Raspbian Wheezy (and have been for a number of years). I want to allow one of my other computers to remotely issue doveadm commands to my server but can’t seem to find the right way to add an inet listener to permit this.
> Using ‘doveconf -a’ I’ve found the default service definition for doveadm-server. So I copied that and added it to the dovecot configuration with an inet listener section added to it. But that was rejected as a duplicate service definition when I restarted dovecot. I then tried specifying a “host:port” value for the doveadm_socket_path value but that didn’t work as no listening socket at that port appeared when I restarted dovecot.
> I can’t seem to find in any of the dovecot documentation a way to do this and there seems to be nothing like a “Here’s how to setup doveadm remote access” section in the documentation (which would be most helpful).
> How can I get doveadm-server to listen not only locally (as it’s already doing) but also open an inet port for remote access?

More information about the dovecot mailing list