SMTP API
Our SMTP API allows you to send email transmissions directly from your own mail server (or client). It acts as an intermediary, receiving your SMTP commands, constructing a mail object, and then processing it for transmission creation.
Our SMTP API accepts connections on the following ports:
- 25: Unencrypted
- 465: SSL
- 587: STARTTLS
Sending an Email using SMTP API
This guide outlines the steps to connect and send your first email using our SMTP API. We'll walk you through a basic SMTP transaction using the openssl s_client command-line tool for demonstration purposes.
For sample code in various languages like Java, Python, Node.js, and Go, check out our GitHub repository.
1. Establish a Secure Connection:
openssl s_client -connect smtp-campaigns.zoho.com:587 -starttls smtp -ign_eof -crlf
This command connects to the Zoho Campaigns server on port 587 (standard for secure SMTP) and initiates a TLS handshake using the STARTTLS extension. The -ign_eof option ensures the command doesn't terminate prematurely, and -crlf specifies using CRLF (carriage return, line feed) as the line terminator.
2. Identify Yourself:
EHLO zylker.com
Send the EHLO command followed by your domain name (zylker.com in this example). This introduces your client to the server.
3. Authenticate with API Key:
Use the AUTH LOGIN command to send the API key (refer to Authentication section of the API documentation here).
AUTH LOGIN
334 Username
YXBpa2V5 // base64 encoded value for the string "apikey"
334 Password
MTAwMC4qKioqKioqKioqKioqLioqKioqKio= // base64 encoded password
235 Continue with the mail
4. Specify the Sender:
Use the MAIL FROM command to specify the email address of the sender. Enclose the address in angle brackets < >.
MAIL FROM:<aaron@zylker.com>
250 2.1.0 Sender <aaron@zylker.com> OK
5. Add Recipients:
Use the RCPT TO command for each recipient address. You can add up to 10,000 recipients per email. Enclose each address in angle brackets.
RCPT TO:<aaron.test@gmail.com>
250 2.1.5 Recipient <aaron.test@gmail.com> OK
RCPT TO:<ea.test@zylker.com>
250 2.1.5 Recipient <ea.test@zylker.com> OK
6. Compose the Email (DATA):
- Use the DATA command to indicate the start of the email content.
- Provide the email subject on a separate line.
- Add the email body content.
- Include any optional email metadata prefixed with X-ZCEA-SMTP-DATA: (refer to API documentation for supported metadata).
- End the email content with a single dot (.) on a new line to signal the end of the message.
DATA
354 Ok Send data ending with <CRLF>.<CRLF>
Subject: My first mail using Zoho Campaigns Email API SMTP
X-ZCEA-SMTP-DATA:{"campaign_name":"Summer is here","recipient_data":{"aaron.test@gmail.com":{"name":"Aaron Fletcher","additional_data":{"phone":"+91231241444","country":"CA"},"merge_data":{"first_name":"Aaron"}},"ea.test@zylker.com":{"name":"EA Test","additional_data":{"phone":"+9198762313210","country":"CA"},"merge_data":{"first_name":"EA"}}},"from":{"address":"aaron@zylker.com","name":"Aron Fletcher"}}
Summer Hot Savings, You Don’t Want to Miss.
7. Success:
Upon successful completion of these steps, the server will send a response indicating the email has been accepted or rejected. Refer to 'Error Codes' documentation for information on response codes.