Code Examples
Ready-to-use code examples for sending emails with HeliosSend in various programming languages.
cURL
Command Line
curl -X POST "https://client.heliossend.com/send" \
-H "Content-Type: application/json" \
-H "Authorization: cs_YOUR_API_KEY" \
-d '{
"from": "contact@helioseditor.com",
"to": ["recipient@example.com"],
"subject": "Test Email",
"html": "<p>This is a test email.</p>"
}'Python
Python with requests
import requests
url = "https://client.heliossend.com/send"
headers = {
"Content-Type": "application/json",
"Authorization": "cs_YOUR_API_KEY"
}
payload = {
"from": "contact@helioseditor.com",
"to": ["recipient@example.com"],
"subject": "Test Email",
"html": "<p>This is a test email.</p>"
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())JavaScript (Fetch API)
Browser JavaScript
const response = await fetch('https://client.heliossend.com/send', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'cs_YOUR_CLIENT_SECRET'
},
body: JSON.stringify({
from: 'contact@helioseditor.com',
to: ['recipient@example.com'],
subject: 'Test Email',
html: '<p>This is a test email.</p>'
})
});
const data = await response.json();
console.log(data);Node.js
Node.js with axios
const axios = require('axios');
const sendEmail = async () => {
try {
const response = await axios.post(
'https://client.heliossend.com/send',
{
from: 'contact@helioseditor.com',
to: ['recipient@example.com'],
subject: 'Test Email',
html: '<p>This is a test email.</p>'
},
{
headers: {
'Content-Type': 'application/json',
'Authorization': 'cs_YOUR_CLIENT_SECRET'
}
}
);
console.log(response.data);
} catch (error) {
console.error('Error:', error.response?.data || error.message);
}
};
sendEmail();PHP
PHP
<?php
$url = 'https://client.heliossend.com/send';
$data = [
'from' => 'contact@helioseditor.com',
'to' => ['recipient@example.com'],
'subject' => 'Test Email',
'html' => '<p>This is a test email.</p>'
];
$options = [
'http' => [
'header' => [
'Content-Type: application/json',
'Authorization: cs_YOUR_CLIENT_SECRET'
],
'method' => 'POST',
'content' => json_encode($data)
]
];
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
echo $result;
?>Full Request Example
Complete Request Body
Example with all optional fields included
{
"from": "contact@helioseditor.com",
"to": ["recipient@example.com"],
"cc": ["cc@example.com"],
"bcc": ["bcc@example.com"],
"subject": "Welcome to HeliosSend!",
"html": "<html><body><h1>Welcome!</h1><p>Thank you for using HeliosSend.</p></body></html>",
"text": "Welcome!\n\nThank you for using HeliosSend.",
"metadata": {
"source": "api",
"campaign": "welcome"
}
}Important Notes
- • Replace
cs_YOUR_API_KEYwith your actual API Key - • The
fromemail domain must be verified in your HeliosSend dashboard - • Never expose your API Key in client-side code or public repositories
- • Use environment variables to store your API Key securely