Tutorial: Send Email from API
Introduction
Section titled “Introduction”In this tutorial, you’ll learn how to send an email using the Contacta API. We’ll walk through the steps required to authenticate, compose your message, and send it programmatically.
Prerequisites
Section titled “Prerequisites”- A Contacta account
- Your API key (find it in your Contacta dashboard)
- Basic knowledge of HTTP requests
- A tool like
curl
, Postman, or any programming language that can make HTTP requests
Step 1: Get Your API Key
Section titled “Step 1: Get Your API Key”Log in to your Contacta dashboard and navigate to the API section. Copy your API key; you’ll need it to authenticate your requests.
Step 2: Compose Your Email Payload
Section titled “Step 2: Compose Your Email Payload”Prepare the JSON payload for your email. Here’s an example:
{ "from": { "name": "John Doe", "email": "john@doe.com" }, "to": [ { "name": "Jane Smith", "email": "jane@smith.com" } ], "subject": "Welcome to Our Service", "text": "Hello, this is a test email.", "html": "<p>Hello, this is a test email.</p>", "variables": { "variable_a_var": "Variable A Value" }, "attachment": [ { "name": "document.pdf", "url": "https://www.buildquickbots.com/whatsapp/media/sample/pdf/sample01.pdf" } ]}
Step 3: Send the Email via API
Section titled “Step 3: Send the Email via API”Now, send a POST request to the Contacta API endpoint with your API key and the payload. Here’s how you can do it with curl
:
curl -X POST https://api.example.com/v1/email/send -H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" -d @payload.json