Creating a Zoho Mail alias using the API

I've been using Zoho Mail for some time, and really like the ability to set up aliases that allow me to send emails from an arbitrary email address on my domain, without setting up a new account.

If you wish to do this against your own account, you can do this through the Mail Admin UI, or alternatively, via the API.

To start off, we'll browse to the Zoho API Console, and create a "Self Client".

Once created, click onto the Self Client, and select the Generate Code.

Specify the scope ZohoMail.organization.accounts.UPDATE (not super clear via) and provide a description, click Create, and then download the result.

Retrieve an access token:

# assuming self_client.json is the downloaded file from the API Console
curl -i https://accounts.zoho.com/oauth/v2/token -d code="$(jq -r .code self_client.json)" -d grant_type=authorization_code -d redirect_uri=https://any.thing.example -d client_id="$(jq -r .client_id self_client.json)" -d client_secret="$(jq -r .client_secret self_client.json)"

This will return an OAuth2 access token and refresh token (pretty-printed for readability):

{
  "access_token": "...",
  "api_domain": "https://www.zohoapis.com",
  "expires_in": 3600,
  "refresh_token": "...",
  "token_type": "Bearer"
}

Retrieve your Zoho User ID (ZUID), which can be found in the Zoho Accounts page if you click your profile picture in the top right.

Retrieve your Zoho Organisation ID (ZOID) from the Zoho Mail Admin Organisation page.

Finally, to add the alias:

export USER_ID=1...
export ORG_ID=1...
export ACCESS_TOKEN=100...
export ALIAS=new@email.domain
curl -i -X PUT -H "Authorization: Zoho-oauthtoken $ACCESS_TOKEN" https://mail.zoho.com/api/organization/$ORG_ID/accounts/$USER_ID -d '{
"zuid": "'$USER_ID'",
   "mode": "addEmailAlias",
   "emailAlias": [
      "'$ALIAS'"
   ]
}' -H 'content-type: application/json'

Written by Jamie Tanna's profile image Jamie Tanna on , and last updated on .

Content for this article is shared under the terms of the Creative Commons Attribution Non Commercial Share Alike 4.0 International, and code is shared under the Apache License 2.0.

#blogumentation #zoho.

This post was filed under articles.

Interactions with this post

Interactions with this post

Below you can find the interactions that this page has had using WebMention.

Have you written a response to this post? Let me know the URL:

Do you not have a website set up with WebMention capabilities? You can use Comment Parade.