Integrating Zoho Mail API in .NET (Without SMTP Issues) - A Complete Guide
If you're using shared hosting (like GoDaddy) or facing SMTP restrictions, switching to the Zoho Mail API is the most reliable solution.
In this guide, we’ll walk through a real-world, working approach to integrate Zoho Mail API in .NET — including common mistakes, fixes, and production-ready tips.
Need a Business Email Platform?
If you're building applications with the Zoho Mail API, consider using Zoho Workplace for professional email hosting, custom domains, calendars, cloud storage, and team collaboration.
Why SMTP Fails (Real Problem)
Many developers start with SMTP:
SmtpClient client = new SmtpClient("smtppro.zoho.in");
client.Port = 587;
client.EnableSsl = false;
But on shared hosting, you may get:
SocketException: access forbidden (port 587)
👉 This happens because:
- Hosting providers block SMTP ports
- SSL/TLS is required
- Authentication fails with SSO accounts
Solution: Use Zoho Mail API
Instead of SMTP, use the REST API provided by Zoho.
✔ Works on any hosting
✔ No port blocking
✔ Secure OAuth authentication
Step 1: Create OAuth Client
Go to:
👉 https://api-console.zoho.in/
- Create Server-based application
- Add redirect URI (e.g.,
http://localhost) - Copy:
- Client ID
- Client Secret
Step 2: Generate Authorization Code
Open this URL in browser:
https://accounts.zoho.in/oauth/v2/auth?
scope=ZohoMail.messages.CREATE,ZohoMail.accounts.READ
&client_id=YOUR_CLIENT_ID
&response_type=code
&access_type=offline
&redirect_uri=http://localhost
👉 After login, you’ll get:
http://localhost/?code=1000.xxxxx
Step 3: Get Refresh Token
POST:
https://accounts.zoho.in/oauth/v2/token
Body:
grant_type=authorization_code
client_id=YOUR_CLIENT_ID
client_secret=YOUR_CLIENT_SECRET
redirect_uri=http://localhost
code=AUTH_CODE
👉 Response includes:
refresh_token✅ (store this safely)
Step 4: Get Access Token
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string,string>("refresh_token","YOUR_REFRESH_TOKEN"),
new KeyValuePair<string,string>("client_id","YOUR_CLIENT_ID"),
new KeyValuePair<string,string>("client_secret","YOUR_CLIENT_SECRET"),
new KeyValuePair<string,string>("grant_type","refresh_token")
});
var response = await client.PostAsync(
"https://accounts.zoho.in/oauth/v2/token",
content);
👉 Access token expires in ~1 hour
Step 5: Get Account ID
Call:
GET https://mail.zoho.in/api/accounts
Header:
Authorization: Zoho-oauthtoken ACCESS_TOKEN
👉 Response:
{
"data": [
{
"accountId": "123456789",
"emailAddress": "info@niceonecode.com"
}
]
}
Step 6: Send Email via API
Endpoint:
POST https://mail.zoho.in/api/accounts/{accountId}/messages
Headers:
Authorization: Zoho-oauthtoken ACCESS_TOKEN
Content-Type: application/json
Body:
{
"fromAddress": "NiceOneCode <info@niceonecode.com>",
"toAddress": "user@gmail.com",
"subject": "Test Email",
"content": "Hello from Zoho API",
"mailFormat": "html"
}
.NET Working Code
var client = new HttpClient();
client.DefaultRequestHeaders.Add(
"Authorization",
"Zoho-oauthtoken " + accessToken);
var json = @"{
""fromAddress"": ""NiceOneCode <info@niceonecode.com>"",
""toAddress"": ""test@gmail.com"",
""subject"": ""Test"",
""content"": ""Hello from Zoho API"",
""mailFormat"": ""html""
}";
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync(
$"https://mail.zoho.in/api/accounts/{accountId}/messages",
content);
Final Verdict
If you’re building production apps:
👉 Use Zoho Mail API instead of SMTP
✔ Works on shared hosting
✔ More secure
✔ No firewall issues
