/go/mail: mail from the Command Line

/go/mail creates and manages the email accounts of hosted domains. Depending on –action, it can: Most actions end by starting /go/vmail in the background, which rebuilds the mail maps for Postfix and Dovecot. A change usually takes effect a few seconds after the command finishes. Every admin action in GoAdmio has a matching /go/ command, so anything you can click you can also script.

Quick start

# Add an address
/go/mail --action add --email info@example.com --domain example.com --pass 'S3cure-Pass9'

# Change its password
/go/mail --action edit --email info@example.com --pass 'N3w-Pass-42'

[!WARNING]
Always pass --action add to create an account, and always pass --pass. Without --action add, nothing is created. Without --pass, the account is created with an empty password. Passwords are also written to the log in plain text. See Security.

Options

Actions

--action What it does Needs
add Creates the account, its mailbox folder, and prints the connection settings. --email, --pass, and --domain
edit Sets a new password. --email, --pass
suspend Marks the account as suspended. --email
unsuspend Removes the suspension. --email
delete Removes the account. See Known limitations for the mailbox files. --email, --domain
default Makes the address the catch-all of its domain. --email, --domain
create Creates accounts for the mailbox folders found under /home/<domain>/mail. --domain

If --action is missing or isn’t one of these, the command only checks the address and the domain, clears any rejection entry for the address, and rebuilds the mail maps. It creates nothing and prints no error.

Settings

Option Used by Notes
--email All actions except create The full address, such as info@example.com. For add, it must be a valid address on a domain hosted on this server.
--pass add, edit The password. Avoid single quotes (') in it.
--domain add, delete, default, create The hosted domain. For add, it is used to look up the account’s system username, so pass it even though the domain also appears in the address.
--forwardto add Forwarding address. Stored with the account.
--keepcopy add Stored with the account, normally used with --forwardto.
--reject add Stored with the account.
--rejectmessage add Stored with the account.
--defaultaddress add Stored with the account.
--suspend add Stored with the account.
--admin add Stored with the account.
--description add A note about the account.
--norestart All actions that rebuild the maps 1 skips the background vmail rebuild.
--timestamp None Accepted, but ignored. The current time is always used.

Settings you don’t pass are stored as empty values.

Examples

# Add an address
/go/mail --action add --email info@example.com --domain example.com --pass 'S3cure-Pass9'

# Add an address that forwards to another one
/go/mail --action add --email sales@example.com --domain example.com --pass 'S3cure-Pass9' \
--forwardto owner@example.org

# Add several addresses, then rebuild the mail maps once
/go/mail --action add --email a@example.com --domain example.com --pass 'Pass-One-1' --norestart 1
/go/mail --action add --email b@example.com --domain example.com --pass 'Pass-Two-2' --norestart 1
/go/vmail

# Change a password
/go/mail --action edit --email info@example.com --pass 'N3w-Pass-42'

# Suspend and unsuspend an address
/go/mail --action suspend --email info@example.com
/go/mail --action unsuspend --email info@example.com

# Delete an address
/go/mail --action delete --email info@example.com --domain example.com

# Send all mail for unknown addresses to info@example.com
/go/mail --action default --email info@example.com --domain example.com

# Recreate accounts from the folders under /home/example.com/mail
/go/mail --action create --domain example.com

# Restart the mail services
/go/mail restart

Output

add

A single line of JSON with the connection settings for the new account. It prints "success": true whenever the command reaches this point, so don’t rely on it to prove that the account exists.

{
"success": true,
"title": "creating_email_account",
"result": {
"incoming_mail_server_imap": "",
"account_type": "IMAP",
"imap_username": "info@example.com",
"imap_hostname": "imap.example.com",
"imap_port": "993",
"imap_encryption": "SSL",
"null": "",
"outgoing_mail_server_smtp": "",
"smtp_username": "info@example.com",
"smtp_hostname": "smtp.example.com",
"smtp_port": "465",
"smtp_encryption": "SSL"
}
}

The real output is one line; it is formatted here for readability. The password is not included.

The host names and ports depend on the SSL certificates on the server:

Condition IMAP SMTP
The domain has a Let’s Encrypt certificate imap.<domain>, port 993, SSL smtp.<domain>, port 465, SSL
Otherwise, the server hostname has one The IMAP hostname (from /etc/imap, or the server hostname), port 993, SSL The server hostname, port 465, SSL
Neither imap.<domain>, port 143, no encryption smtp.<domain>, port 25, no encryption

If the server setting IMAPAlert is 1, the new address also receives its configuration by email, sent in the background with outlook.

Other actions

Action Message
default with --email GoAdmio will forward all unrouted email for <domain> to <email>.
default without an address GoAdmio will forward all unrouted email for <domain> to 'Recipient address rejected: User unknown.' (see Known limitations)
delete <email> has been deleted.
suspend <email> has been suspended.
unsuspend <email> has been unsuspended.
edit <email> Password has been modified successfully. The line written to Dovecot’s password file is also printed.

Errors and exit status

Message Meaning Exit status
MAIL: Unknown parameter: <option> A misspelled or unsupported option. 1
Invalid Email Address <email>. The address isn’t valid. 1
Account <domain> not exists The domain isn’t hosted on this server. 1

restart and edit always exit with status 1, even when they work. Read the output, not the exit status.

See the full reference at /go/mail and the GoAdmio command index.

GoAdmio is free and open source, with no license fees and no account limits. Read the GoAdmio docs, or see why it is a free cPanel alternative at goadmio.com.

By:

Posted in:


Leave a Reply

Your email address will not be published. Required fields are marked *