<!doctype html>
<html>
 <head>
  <meta charset="UTF-8">
 </head>
 <body>
  <div>
   You could instead use Dovecot's HTTP API. See <a href="https://doc.dovecot.org/admin_manual/doveadm_http_api/">https://doc.dovecot.org/admin_manual/doveadm_http_api/</a>
  </div>
  <div class="default-style">
    
  </div>
  <div class="default-style">
   Aki
  </div>
  <blockquote type="cite">
   <div>
    On 18/03/2023 16:13 EET Paul Kudla <<a href="mailto:paul@scom.ca">paul@scom.ca</a>> wrote:
   </div>
   <div>
     
   </div>
   <div>
     
   </div>
   <div>
    ok there might be other ways to do this but here is what i did for my
   </div>
   <div>
    django project
   </div>
   <div>
     
   </div>
   <div>
    I had to create a listener in python
   </div>
   <div>
     
   </div>
   <div>
    PLEASE PLEASE PLEASE BE CAREFUL !
   </div>
   <div>
     
   </div>
   <div>
    This script is designed to work on a closed network and is still rough
   </div>
   <div>
    around the edges but does work
   </div>
   <div>
     
   </div>
   <div>
    needs to be run as root in the background to access the doveadm.
   </div>
   <div>
     
   </div>
   <div>
    If you intend to access from outside then you need to secure it by
   </div>
   <div>
    static ip, username/password etc ???
   </div>
   <div>
     
   </div>
   <div>
    The client side code sends an email to notify you when the script is
   </div>
   <div>
    accessed?
   </div>
   <div>
     
   </div>
   <div>
    Can help if you get stuck.
   </div>
   <div>
     
   </div>
   <div>
    _____________________________________________________________________
   </div>
   <div>
     
   </div>
   <div>
    # cat /sbin/scripts/dovecot.listen
   </div>
   <div>
    #!/usr/local/bin/python2
   </div>
   <div>
     
   </div>
   <div>
    import os,sys
   </div>
   <div>
    import socket
   </div>
   <div>
    import commands
   </div>
   <div>
    import time
   </div>
   <div>
     
   </div>
   <div>
    from lib import *
   </div>
   <div>
     
   </div>
   <div>
    a = onlyone ('dovecot.listen')
   </div>
   <div>
    if a.status == 'BAD' :
   </div>
   <div>
    print 'Another Process Is running ....'
   </div>
   <div>
    sys.exit()
   </div>
   <div>
     
   </div>
   <div>
    TCP_IP = '10.220.0.18'
   </div>
   <div>
    TCP_PORT = 8444
   </div>
   <div>
    BUFFER_SIZE = 1024 # Normally 1024, but we want fast response
   </div>
   <div>
     
   </div>
   <div>
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
   </div>
   <div>
    s.bind((TCP_IP, TCP_PORT))
   </div>
   <div>
    s.listen(1)
   </div>
   <div>
     
   </div>
   <div>
    while 1 : #Process received data?
   </div>
   <div>
    conn, addr = s.accept() #Wait for data
   </div>
   <div>
    print 'Connection address:', addr
   </div>
   <div>
    data = conn.recv(BUFFER_SIZE)
   </div>
   <div>
    if not data: break
   </div>
   <div>
    print "received data:", data
   </div>
   <div>
    data = data.split (' ')
   </div>
   <div>
    command = data[0]
   </div>
   <div>
    print command
   </div>
   <div>
     
   </div>
   <div>
    #If CM (Create Mailbox)
   </div>
   <div>
    if command == 'CM' :
   </div>
   <div>
    username = data[1]
   </div>
   <div>
    print 'Creating Email Account : %s' % (username)
   </div>
   <div>
    #Now create the mail box
   </div>
   <div>
    #Now go make the email account
   </div>
   <div>
    message = ''
   </div>
   <div>
    for n in range (0,100) :
   </div>
   <div>
    command1 =
   </div>
   <div>
    commands.getoutput('/usr/local/bin/doveadm mailbox create -s -u %s
   </div>
   <div>
    INBOX' %str(username))
   </div>
   <div>
    print 'Command1 : %s' %command1
   </div>
   <div>
    if 'Mailbox already exists' in command1 :
   </div>
   <div>
    message = 'BAD'
   </div>
   <div>
    conn.send( str(message) )
   </div>
   <div>
    break
   </div>
   <div>
     
   </div>
   <div>
    else :
   </div>
   <div>
    if message == '' :
   </div>
   <div>
    message = 'OK'
   </div>
   <div>
    conn.send(message)
   </div>
   <div>
    message = 'SENT'
   </div>
   <div>
     
   </div>
   <div>
    if "User doesn't exist" in command1 :
   </div>
   <div>
    time.sleep(2)
   </div>
   <div>
    continue
   </div>
   <div>
    else :
   </div>
   <div>
    print 'Command1 : %s' %command1
   </div>
   <div>
    message = 'SENT'
   </div>
   <div>
    break
   </div>
   <div>
     
   </div>
   <div>
    if message == 'SENT' : #Create the rest
   </div>
   <div>
    command2 =
   </div>
   <div>
    commands.getoutput('/usr/local/bin/doveadm mailbox create -s -u %s Sent'
   </div>
   <div>
    %str(username))
   </div>
   <div>
    print 'Command2 : %s' %command2
   </div>
   <div>
    command3 =
   </div>
   <div>
    commands.getoutput('/usr/local/bin/doveadm mailbox create -s -u %s
   </div>
   <div>
    Trash' %str(username))
   </div>
   <div>
    print 'Command3 : %s' %command3
   </div>
   <div>
    command4 =
   </div>
   <div>
    commands.getoutput('/usr/local/bin/doveadm mailbox create -s -u %s
   </div>
   <div>
    Drafts' %str(username))
   </div>
   <div>
    print 'Command4 : %s' %command4
   </div>
   <div>
     
   </div>
   <div>
     
   </div>
   <div>
     
   </div>
   <div>
     
   </div>
   <div>
    if command == 'INFO' :
   </div>
   <div>
    username = data[1]
   </div>
   <div>
    print 'Getting Email Account Info : %s' % ( username )
   </div>
   <div>
    command1 = commands.getoutput("/usr/local/bin/doveadm
   </div>
   <div>
    mailbox status -t all -u %s '*' " %str(username))
   </div>
   <div>
    if 'Error' in command1 :
   </div>
   <div>
    message = 'BAD'
   </div>
   <div>
    else :
   </div>
   <div>
    message = 'OK : ' + command1
   </div>
   <div>
     
   </div>
   <div>
    print message
   </div>
   <div>
    conn.send( str(message) ) # echo
   </div>
   <div>
     
   </div>
   <div>
     
   </div>
   <div>
    if command == 'DM' :
   </div>
   <div>
    data = data[1]
   </div>
   <div>
    data = data.split('@')
   </div>
   <div>
    print 'Deleting Email Account : user/%s@%s' % (
   </div>
   <div>
    str(data[0]), str(data[1]) )
   </div>
   <div>
     
   </div>
   <div>
    message = 'BAD'
   </div>
   <div>
     
   </div>
   <div>
    conn.send(message) # echo
   </div>
   <div>
    print message
   </div>
   <div>
     
   </div>
   <div>
     
   </div>
   <div>
     
   </div>
   <div>
    conn.close()
   </div>
   <div>
    s.close()
   </div>
   <div>
     
   </div>
   <div>
     
   </div>
   <div>
     
   </div>
   <div>
     
   </div>
   <div>
    #Go Back Around
   </div>
   <div>
     
   </div>
   <div>
    _______________________________________________________________________
   </div>
   <div>
     
   </div>
   <div>
    and then in django / or outside ? :
   </div>
   <div>
     
   </div>
   <div>
    _______________________________________________________________________
   </div>
   <div>
     
   </div>
   <div>
    #Try to get info for this account
   </div>
   <div>
    if dontupdate == False :
   </div>
   <div>
     
   </div>
   <div>
    imap_test = Dovecot_Command ('INFO',self.username) #do i have
   </div>
   <div>
    this account ?
   </div>
   <div>
     
   </div>
   <div>
    if 'BAD' in imap_test.answer :
   </div>
   <div>
    try : #Try to Create the account, note that the db must be
   </div>
   <div>
    updated properly before it will work
   </div>
   <div>
    imap_create = Dovecot_Command ('CM',self.username)
   </div>
   <div>
    if 'OK' in imap_create.answer :
   </div>
   <div>
    send_subject = 'Email Account Created : %s'
   </div>
   <div>
    %(str(self.username) )
   </div>
   <div>
     
   </div>
   <div>
    except :
   </div>
   <div>
    send_subject = 'Error Account : %s' %(str(self.username) )
   </div>
   <div>
    pass
   </div>
   <div>
     
   </div>
   <div>
    else :
   </div>
   <div>
    send_subject = 'Email Account Updated : %s' %(self.username)
   </div>
   <div>
     
   </div>
   <div>
    #Send update email
   </div>
   <div>
     
   </div>
   <div>
    send_from = <a href="mailto:'monitor@scom.ca">'monitor@scom.ca</a>'
   </div>
   <div>
    send_files = []
   </div>
   <div>
    send_to = [<a href="mailto:'monitor@scom.ca">'monitor@scom.ca</a>']
   </div>
   <div>
    send_text = '\n\n'+ send_subject + '\n'
   </div>
   <div>
    sendmail(send_from,send_to,send_subject,send_text,send_files)
   </div>
   <div>
    #Send the warning email
   </div>
   <div>
     
   </div>
   <div>
     
   </div>
   <div>
     
   </div>
   <div>
     
   </div>
   <div>
    if send_settings != '' : #Send Email Setup to this address
   </div>
   <div>
    servername = 'mail.%s' %domain
   </div>
   <div>
     
   </div>
   <div>
    send_from = <a href="mailto:'info@scom.ca">'info@scom.ca</a>'
   </div>
   <div>
    send_files = []
   </div>
   <div>
    send_to = ['%s' %send_settings,]
   </div>
   <div>
     
   </div>
   <div>
    send_subject = 'Email Setup Instructions for : %s %s'
   </div>
   <div>
    %(emailaddress,send_settings)
   </div>
   <div>
     
   </div>
   <div>
    #Assemblt the sxend text with the info
   </div>
   <div>
     
   </div>
   <div>
    _____________________________________________________________________
   </div>
   <div>
     
   </div>
   <div>
     
   </div>
   <div>
     
   </div>
   <div>
    Happy Saturday !!!
   </div>
   <div>
    Thanks - paul
   </div>
   <div>
     
   </div>
   <div>
    Paul Kudla
   </div>
   <div>
     
   </div>
   <div>
     
   </div>
   <div>
    Scom.ca Internet Services <<a href="http://www.scom.ca" target="_blank" rel="noopener">http://www.scom.ca</a>>
   </div>
   <div>
    004-1009 Byron Street South
   </div>
   <div>
    Whitby, Ontario - Canada
   </div>
   <div>
    L1N 4S3
   </div>
   <div>
     
   </div>
   <div>
    Toronto 416.642.7266
   </div>
   <div>
    Main 1.866.411.7266
   </div>
   <div>
    Fax 1.888.892.7266
   </div>
   <div>
    Email <a href="mailto:paul@scom.ca">paul@scom.ca</a>
   </div>
   <div>
     
   </div>
   <div>
    On 3/17/2023 10:22 PM, <a href="mailto:dovecot-bounces@dovecot.org">dovecot-bounces@dovecot.org</a> wrote:
   </div>
   <blockquote type="cite">
    <div>
     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.
    </div>
    <div>
      
    </div>
    <div>
     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.
    </div>
    <div>
      
    </div>
    <div>
     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).
    </div>
    <div>
      
    </div>
    <div>
     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?
    </div>
    <div>
      
    </div>
   </blockquote>
  </blockquote>
 </body>
</html>