mailcow / mailcow-dockerized

mailcow: dockerized - 🐮 + 🐋 = 💕
https://mailcow.email
GNU General Public License v3.0
9.03k stars 1.18k forks source link

Set recovery_email while Creating a mailbox via API #6072

Open mostafa0017 opened 2 months ago

mostafa0017 commented 2 months ago

Summary

Currently, If I sent a get request to get a mailbox I receive:

[
    {
        "username": "test@example.com",
        "active": 1,
        "active_int": 1,
        "domain": "example.com",
        "name": "Joe Doe",
        "local_part": "test",
        "quota": 0,
        "messages": 31,
        "attributes": {
            "force_pw_update": "0",
            "tls_enforce_in": "1",
            "tls_enforce_out": "1",
            "sogo_access": "0",
            "imap_access": "1",
            "pop3_access": "1",
            "smtp_access": "1",
            "sieve_access": "1",
            "relayhost": "0",
            "passwd_update": "2024-09-03 15:31:39",
            "mailbox_format": "maildir:",
            "quarantine_notification": "hourly",
            "quarantine_category": "reject",
            "recovery_email": "recovery@fortest.com"
        },
        "custom_attributes": [],
        "quota_used": 121623,
        "percent_in_use": "- ",
        "created": "2024-09-01 12:56:24",
        "modified": "2024-09-05 14:19:00",
        "percent_class": "info",
        "last_imap_login": 1725969402,
        "last_smtp_login": 1725959252,
        "last_pop3_login": 0,
        "max_new_quota": 9269411840,
        "spam_aliases": 0,
        "pushover_active": 0,
        "rl": false,
        "rl_scope": "domain",
        "is_relayed": 0,
        "tags": [
            "Staff"
        ]
    }
]

So I wanted to use recovery_email in a POST request to create a mailbox, but sadly this value is ignored if I tried and a mailbox gets created without it.

Motivation

It would benefit all the API users by adding another value to be set while creating a mailbox.

Additional context

No response

DerLinkman commented 2 months ago

Is there no endpoint in the API @FreddleSpl0it?

samirss56 commented 1 month ago

So I wanted to use recovery_email in a POST request to create a mailbox, but sadly this >value is ignored if I tried and a mailbox gets created without it.

edit file /opt/mailcowdockerized/data/web/inc/functions.mailbox.inc.php

goto line 1079: add recovery_email as follows:

1078 $recovery_email = (isset($_data['recovery_email'])) ? strval($_data['recovery_email']) : strval($MAILBOX_DEFAULT_ATTRIBUTES['recovery_email']);

1079 $mailbox_attrs = json_encode( 1080

goto line 1094: add recovery_email as follows:

1094 'attribute_hash' => $attribute_hash, 1095 'recovery_email' => $recovery_email

docker compose down ; docker compose up -d

curl example to create mailbox with recovery email:

curl -v -X 'POST' \ 'https://your-maildoain.tld/api/v1/add/mailbox' \ -H 'X-API-Key: your api-key' \ -H 'Content-Type: application/json' \ -d '{ "active": "1", "domain": "yourdomain.tld", "local_part": "info3", "name": "Full name", "password": "123123", "password2": "123123", "quota": "3072", "force_pw_update": "0", "tls_enforce_in": "1", "tls_enforce_out": "1", "recovery_email": "recovery_email@hotmail.com" }'