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 <paul@scom.ca> wrote:
 
 
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
 
PLEASE PLEASE PLEASE BE CAREFUL !
 
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
accessed?
 
Can help if you get stuck.
 
_____________________________________________________________________
 
# cat /sbin/scripts/dovecot.listen
#!/usr/local/bin/python2
 
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 ....'
sys.exit()
 
TCP_IP = '10.220.0.18'
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))
s.listen(1)
 
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) )
break
 
else :
if message == '' :
message = 'OK'
conn.send(message)
message = 'SENT'
 
if "User doesn't exist" in command1 :
time.sleep(2)
continue
else :
print 'Command1 : %s' %command1
message = 'SENT'
break
 
if message == 'SENT' : #Create the rest
command2 =
commands.getoutput('/usr/local/bin/doveadm mailbox create -s -u %s Sent'
%str(username))
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
 
 
 
conn.close()
s.close()
 
 
 
 
#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) )
pass
 
else :
send_subject = 'Email Account Updated : %s' %(self.username)
 
#Send update email
 
send_from = 'monitor@scom.ca'
send_files = []
send_to = ['monitor@scom.ca']
send_text = '\n\n'+ send_subject + '\n'
sendmail(send_from,send_to,send_subject,send_text,send_files)
#Send the warning email
 
 
 
 
if send_settings != '' : #Send Email Setup to this address
servername = 'mail.%s' %domain
 
send_from = 'info@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 - paul
 
Paul Kudla
 
 
Scom.ca Internet Services <http://www.scom.ca>
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@scom.ca
 
On 3/17/2023 10:22 PM, dovecot-bounces@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?