MailcowApiClient

mailcow-api. MailcowApiClient

Class representing the Mailcow API client

Constructor

new MailcowApiClient(baseurl, apikey)

Source:
Create a Mailcow API client.
Example
(async () => {
    //get global variables
    require('dotenv').config();
    
    //import the api client module
    const {
        MailcowApiClient
    } = require("mailcow-api")

    //create new mailcow api client with endpoint/baseurl and the api key
    const mcc = new MailcowApiClient(process.env.MAILCOW_API_BASEURL, process.env.MAILCOW_API_KEY);

    //get all domain on mailcow server
    console.log(await mcc.getDomain());
})();
Parameters:
Name Type Description
baseurl string The base url where the api can be found
apikey string The api key for the mailcow api endpoint

Methods

(async) addAlias(address, goto) → {Boolean}

Source:
Adds an alias for a mailbox
Example
await mcc.addAlias("@test.tld","mail@example.com")
        //This will catch all mail for the domain test.tld and put it in the mailbox mail@example.com
Parameters:
Name Type Description
address String alias address, for catchall use "@domain.tld"
goto String destination address, comma separated
Returns:
true on success
Type
Boolean

(async) addAndGetDKIM(dkim) → {Object}

Source:
Generates a DKIM domain key for a domain and returns it
Example
await mcc.addAndGetDKIM({
            domain: "example.com",
        })
        //This will generate a DKIM key for example.com on the mailcow server and return it
Parameters:
Name Type Description
dkim String | DKIM A DKIM object or string
Returns:
DKIM key on success
Type
Object

(async) addDKIM(dkim) → {Boolean}

Source:
Generates a DKIM domain key for a domain
Example
await mcc.addDKIM({
            domain: "example.com",
        })
        //This will generate a DKIM key for example.com on the mailcow server
Parameters:
Name Type Description
dkim String | DKIM A DKIM object or string
Returns:
True on success
Type
Boolean

(async) addDomain(domain) → {Boolean}

Source:
Adds a domain to the server
Example
await mcc.addDomain({
            domain: "example.com",
        }))
Parameters:
Name Type Description
domain String | Domain The domain you want to add
Returns:
True on success
Type
Boolean

(async) addDomainAdmin(domainAdmin) → {Object}

Source:
Adds a domain admin to the mailcow server
Example
await mcc.addDomainAdmin({
            domains: ['example.com', 'example.org']
        })
        //This will add an admin for the domains example.com and example.org and return their credentials
Parameters:
Name Type Description
domainAdmin DomainAdmin a domain admin object that has to contain at least the domains the admin should be able to control
Returns:
containing password username and domains on successfull creation
Type
Object

(async) addMailbox(mailbox) → {Object}

Source:
Adds a mailbox for a domain to the mailcow server
Example
await mcc.addMailbox({
            domain: 'example.com',
            name: 'Example'
        })
        //This will add a mailbox for the domain example.com and return it 
Parameters:
Name Type Description
mailbox Mailbox a Mailbox object that has to contain at least the domain for which the mailbox shall be created
Returns:
the created mailbox
Type
Object

(async) deleteDKIM(domain) → {Boolean}

Source:
Deletes the DKIM key for a domain on the mailcow server
Example
await mcc.deleteDKIM('example.com')
        //This will delete the DKIM key for the domain example.com from the mailcow server
Parameters:
Name Type Description
domain Array the domain name/names you want to delete the key for
Returns:
true on success
Type
Boolean

(async) deleteDomain(domain) → {Boolean}

Source:
Removes a domain from the server
Example
await mcc.deleteDomain("example.com")
Parameters:
Name Type Description
domain String | Array The domain/domains you want to delete
Returns:
True on success
Type
Boolean

(async) deleteMailbox(mailboxes) → {Boolean}

Source:
Deletes a mailbox
Example
await mcc.deleteMailbox("mail@example.com")
        //This will delete the mailbox mail@example.com
Parameters:
Name Type Description
mailboxes String | Array complete name of the mailbox/mailboxes
Returns:
true on success
Type
Boolean

(async) editDomain(domains, attributes) → {Boolean}

Source:
Edits one or more domains on the server. Applies the attributes to all domains provided.
Example
await mcc.editDomain(["example.com"], {
            aliases: 399
        });
        //This will set the aliases of example.com to 399
Parameters:
Name Type Description
domains Array | String The domains you want to edit
attributes Object Attributes to change for all domains provided domains
Returns:
True on success
Type
Boolean

(async) getDKIM(domain) → {Object}

Source:
Gets the DKIM key for a domain on the mailcow server
Example
await mcc.getDKIM('example.com')
        //This will get the DKIM key for the domain example.com from the mailcow server
Parameters:
Name Type Description
domain String the domain name you want to get the key for
Returns:
The DKIM public key and other parameters
Type
Object

(async) getDomain(domainopt) → {Array}

Source:
Gets a specific domain or all domains
Example
await mcc.getDomain()
Parameters:
Name Type Attributes Default Description
domain String <optional>
'all' The domain you want to get
Returns:
Array of domains
Type
Array