You could instead use Dovecot's HTTP API. See https://doc.dovecot.org/admin_manual/doveadm_http_api/
Aki
On 18/03/2023 16:13 EET Paul Kudla <p...@scom.ca> wrote:ok there might be other ways to do this but here is what i did for mydjango projectI had to create a listener in pythonPLEASE PLEASE PLEASE BE CAREFUL !This script is designed to work on a closed network and is still rougharound the edges but does workneeds 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 bystatic ip, username/password etc ???The client side code sends an email to notify you when the script isaccessed?Can help if you get stuck._____________________________________________________________________# cat /sbin/scripts/dovecot.listen#!/usr/local/bin/python2import os,sysimport socketimport commandsimport timefrom lib import *a = onlyone ('dovecot.listen')if a.status == 'BAD' :print 'Another Process Is running ....'sys.exit()TCP_IP = '10.220.0.18'TCP_PORT = 8444BUFFER_SIZE = 1024 # Normally 1024, but we want fast responses = socket.socket(socket.AF_INET, socket.SOCK_STREAM)s.bind((TCP_IP, TCP_PORT))s.listen(1)while 1 : #Process received data?conn, addr = s.accept() #Wait for dataprint 'Connection address:', addrdata = ""if not data: breakprint "received data:", datadata = "" (' ')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 accountmessage = ''for n in range (0,100) :command1 =commands.getoutput('/usr/local/bin/doveadm mailbox create -s -u %sINBOX' %str(username))print 'Command1 : %s' %command1if 'Mailbox already exists' in command1 :message = 'BAD'conn.send( str(message) )breakelse :if message == '' :message = 'OK'conn.send(message)message = 'SENT'if "User doesn't exist" in command1 :time.sleep(2)continueelse :print 'Command1 : %s' %command1message = 'SENT'breakif message == 'SENT' : #Create the restcommand2 =commands.getoutput('/usr/local/bin/doveadm mailbox create -s -u %s Sent'%str(username))print 'Command2 : %s' %command2command3 =commands.getoutput('/usr/local/bin/doveadm mailbox create -s -u %sTrash' %str(username))print 'Command3 : %s' %command3command4 =commands.getoutput('/usr/local/bin/doveadm mailbox create -s -u %sDrafts' %str(username))print 'Command4 : %s' %command4if command == 'INFO' :username = data[1]print 'Getting Email Account Info : %s' % ( username )command1 = commands.getoutput("/usr/local/bin/doveadmmailbox status -t all -u %s '*' " %str(username))if 'Error' in command1 :message = 'BAD'else :message = 'OK : ' + command1print messageconn.send( str(message) ) # echoif command == 'DM' :data = ""data = ""print 'Deleting Email Account : user/%s@%s' % (str(data[0]), str(data[1]) )message = 'BAD'conn.send(message) # echoprint messageconn.close()s.close()#Go Back Around_______________________________________________________________________and then in django / or outside ? :_______________________________________________________________________#Try to get info for this accountif dontupdate == False :imap_test = Dovecot_Command ('INFO',self.username) #do i havethis account ?if 'BAD' in imap_test.answer :try : #Try to Create the account, note that the db must beupdated properly before it will workimap_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) )passelse :send_subject = 'Email Account Updated : %s' %(self.username)#Send update emailsend_from = 'moni...@scom.ca'send_files = []send_to = ['moni...@scom.ca']send_text = '\n\n'+ send_subject + '\n'sendmail(send_from,send_to,send_subject,send_text,send_files)#Send the warning emailif send_settings != '' : #Send Email Setup to this addressservername = 'mail.%s' %domainsend_from = 'i...@scom.ca'send_files = []send_to = ['%s' %send_settings,]send_subject = 'Email Setup Instructions for : %s %s'%(emailaddress,send_settings)#Assemblt the sxend text with the info_____________________________________________________________________Happy Saturday !!!Thanks - paulPaul KudlaScom.ca Internet Services <http://www.scom.ca>004-1009 Byron Street SouthWhitby, Ontario - CanadaL1N 4S3Toronto 416.642.7266Main 1.866.411.7266Fax 1.888.892.7266Email p...@scom.caOn 3/17/2023 10:22 PM, dovecot-boun...@dovecot.org 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?