[SOLVED]After creating new mail_user via SOAP API, email sent from user are not moved to Sent folder

Discussion in 'Programming/Scripts' started by bobcatfish, Mar 12, 2021.

  1. bobcatfish

    bobcatfish New Member

    Hello,
    I'm using the SOAP API to create new mail_users. Creation is working great. However, I'm experiencing some differences between mail_users created via the SOAP API and mail_users created via the ISPConfig3 WebUI.

    Here's the process around the issue:
    • Create new mail_user via SOAP API (code example below)
    • Login using Squirrelmail as newly created mail_user
    • Send an email
    • `Sent` folder is empty
      • This is unexpected. Expectation is that the sent email would be displayed here
    • Create new mail_user via ISPConfig3 WebUI via Email -> new Email Mailbox
    • Login using Squirrelmail as newly created mail_user
    • Send an email
    • `Sent` folder contains the newly sent email as expected
    In both scenarios, the sent email is delivered successfully to the intended recipient.
    Here is the code I'm using to create the new mail_user via the SOAP API:

    PHP:
                    $client = new SoapClient(null, array('location' => $soap_location,
                            
    'uri'   => $soap_uri,
                            
    'trace' => 1,
                            
    'exceptions' => 1));

                            
    $client_id 1;
                            
    $params = array(
                                    
    'server_id' => 1,
                                    
    'email' => '[email protected]',
                                    
    'login' => '[email protected]',
                                    
    'password' => 'bestpasswordever,
                                    '
    quota' => 54200000,
                                    '
    maildir' => '/var/vmail/mydomain.com/testuser',
                                    '
    homedir' => '/var/vmail',
                                    '
    cc' => 'audit@mydomain.com',
                                    '
    sender_cc' => 'audit@mydomain.com',
                                    '
    move_junk' => 'y',
                                    '
    autoresponder_text' => NULL,
                                    '
    autoresponder_subject' => 'Out of office reply',
                                    '
    postfix' => 'y',
                                    '
    access' => 'y',
                                    '
    disableimap' => 'n',
                                    '
    disabledeliver' => 'n',
                                    '
    disablesmtp' => 'n',
                                    '
    purge_trash_days' => 0,
                                    '
    purge_junk_days' => 0,
                                    '
    backup_interval' => 'none'
                            );

    $mailuser_id = $client->mail_user_add($session_id, $client_id, $params); 
    I'm not sure why the users created via the SOAP API are not getting messages moved in to the `Sent` folder. Is there a step I missed? Another API call I need to make? Something else?
     
  2. Th0m

    Th0m ISPConfig Developer Staff Member ISPConfig Developer

    Before answering anything else on this, you should not be using Squirrelmail in 2021. It hasn't been updated in years and creates a security risk for your emails. You should start using different webmail software like Roundcube.

    It seems like you left out some fields, I don't use the API myself, but I'm not sure if this is allowed. See the example: https://git.ispconfig.org/ispconfig...op/remoting_client/examples/mail_user_add.php

    Do you notice any other problems with the folders of the user created through the API? What happens when you use a different mail client?
     
  3. Jesse Norell

    Jesse Norell ISPConfig Developer Staff Member ISPConfig Developer

    Create a user via the UI and another via the API and compare the fields in the database (mail_user table).
     
  4. bobcatfish

    bobcatfish New Member

    Thanks for the reply Th0m. I get the same problem in Thunderbird as well with folders; newly created users via SOAP API can send email just fine, but the message can never get moved to the `Sent` folder. Which, in Thunderbird, means the dialoge box stays open after the send, while it's trying to move the message to `Sent`.

    I think I purposfully removed the fields that were present in the link you posted. The values in the mail_user table were set to the same values independant on if I made the new mail_user via the SOAP API or via the ISPConfig WebUI. However - adding back in `name`, `uid`, `gid`, `autoresponder_start_date`, autoresponder_end_date`, and `custom_mailfilter` fixed it! I'm now seeing the sent mail show up in the `Sent` folder. Perfect!

    Thanks for the reply Jesse. Comparing the records is how I ended up tacking on fields like `purge_trash_days`, `purge_junk_days`, and `backup_interval`. These were getting set with values when creating a user through the ISPConfig WebUI, but not when I was creating a user via my SOAP API integration. I learned about the `\G` flag at the end of a MySQL statement by doing this!

    Thank you both for replying. It's working as expected now!

    Here's what the code looks like now:
    PHP:
    $client = new SoapClient(null, array('location' => $soap_location,
            
    'uri'   => $soap_uri,
            
    'trace' => 1,
            
    'exceptions' => 1));

    $client_id 1;
    $params = array(
            
    'server_id' => 1,
            
    'email' => '[email protected]',
            
    'login' => '[email protected]',
        
    'name' => 'testuser',
            
    'password' => 'bestpasswordever,
        '
    uid' => 5000,
        '
    gid' => 5000,
            '
    quota' => 54200000,
            '
    maildir' => '/var/vmail/mydomain.com/testuser',
            '
    homedir' => '/var/vmail',
            '
    cc' => 'audit@mydomain.com',
            '
    sender_cc' => 'audit@mydomain.com',
            '
    move_junk' => 'y',
        '
    autoresponder' => 'n',
        '
    autoresponder_start_date' => '',
        '
    autoresponder_end_date' => '',
            '
    autoresponder_text' => NULL,
            '
    autoresponder_subject' => 'Out of office reply',
            '
    postfix' => 'y',
            '
    access' => 'y',
            '
    disableimap' => 'n',
            '
    disabledeliver' => 'n',
            '
    disablesmtp' => 'n',
            '
    purge_trash_days' => 0,
            '
    purge_junk_days' => 0,
            '
    backup_interval' => 'none'
    );

    $mailuser_id = $client->mail_user_add($session_id, $client_id, $params); 
     
    Th0m likes this.

Share This Page