Send an Email
Learn how to send an email using the Mailofly REST API and SDKs.Endpoint
POST https://api.mailofly.com/api/emails
Authorization: Bearer <YOUR_API_KEY>
Content-Type: application/json
Code Examples
cURL
curl -X POST https://api.mailofly.com/api/emails \
-H "Authorization: Bearer mfly_live_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"from": "Acme <notifications@yourcompany.com>",
"to": ["alex@example.com"],
"subject": "Welcome to Acme!",
"html": "<h1>Welcome, Alex!</h1><p>Thanks for joining Acme.</p>"
}'
Node.js / TypeScript
import { Mailofly } from "mailofly";
const mailofly = new Mailofly("mfly_live_your_api_key");
const { data, error } = await mailofly.emails.send({
from: "Acme <notifications@yourcompany.com>",
to: ["alex@example.com"],
subject: "Welcome to Acme!",
html: "<h1>Welcome, Alex!</h1><p>Thanks for joining Acme.</p>",
});
if (error) {
console.error("Failed to send email:", error);
} else {
console.log("Email sent! ID:", data.id);
}
Python
from mailofly import Mailofly
client = Mailofly(api_key="mfly_live_your_api_key")
response = client.emails.send({
"from": "Acme <notifications@yourcompany.com>",
"to": ["alex@example.com"],
"subject": "Welcome to Acme!",
"html": "<h1>Welcome, Alex!</h1><p>Thanks for joining Acme.</p>",
})
print(f"Sent email ID: {response['id']}")
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
from | string | Yes | Sender email formatted as name@domain.com or Name <name@domain.com>. |
to | string[] | Yes | List of recipient email addresses (max 50 per single call). |
subject | string | Yes | Email subject line. |
html | string | Optional* | The HTML version of the message. |
text | string | Optional* | Plaintext fallback. |
reply_to | string[] | Optional | Addresses to use when the recipient hits reply. |
cc | string[] | Optional | Carbon copy recipients. |
bcc | string[] | Optional | Blind carbon copy recipients. |
scheduled_at | string | Optional | ISO-8601 string for future scheduling (e.g. 2026-09-15T10:00:00Z). |
attachments | object[] | Optional | Array of attachments with filename and content (base64) or path. |
tags | object | Optional | Key-value pairs for metadata and analytics filtering. |
html, text, or template_id must be supplied.
Response Schema
Success (200 OK)
{
"id": "msg_01J8G52XYZ9A8B7C6D",
"from": "notifications@yourcompany.com",
"to": ["alex@example.com"],
"created_at": "2026-09-11T00:30:00Z"
}