Learn patterns for sending transactional emails with Ark — basic sends, multiple recipients, attachments, metadata, tracking, and error handling in Python, Node.js, Ruby, and Go.
This guide covers common patterns for sending transactional emails with Ark, from simple notifications to complex templates.
Building a white-label platform? You can send emails scoped to specific tenants using tenant_id. See the Architecture Overview for white-label sending patterns.
from ark import Arkclient = Ark()email = client.emails.send( from_="hello@yourdomain.com", to=["user@example.com"], subject="Your order has shipped!", html="<h1>Order Shipped</h1><p>Your order #1234 is on its way.</p>", text="Order Shipped\n\nYour order #1234 is on its way.")print(f"Email sent: {email.data.id}")
import Ark from 'ark';const client = new Ark();const email = await client.emails.send({ from: 'hello@yourdomain.com', to: ['user@example.com'], subject: 'Your order has shipped!', html: '<h1>Order Shipped</h1><p>Your order #1234 is on its way.</p>', text: 'Order Shipped\n\nYour order #1234 is on its way.',});console.log(`Email sent: ${email.data.id}`);
require "ark_email"client = ArkEmail::Client.newemail = client.emails.send_( from: "hello@yourdomain.com", to: ["user@example.com"], subject: "Your order has shipped!", html: "<h1>Order Shipped</h1><p>Your order #1234 is on its way.</p>", text: "Order Shipped\n\nYour order #1234 is on its way.")puts "Email sent: #{email.data.id}"
client := ark.NewClient()email, err := client.Emails.Send(ctx, ark.EmailSendParams{ From: "hello@yourdomain.com", To: []string{"user@example.com"}, Subject: "Your order has shipped!", HTML: ark.String("<h1>Order Shipped</h1><p>Your order #1234 is on its way.</p>"), Text: ark.String("Order Shipped\n\nYour order #1234 is on its way."),})
curl -X POST https://api.arkhq.io/v1/emails \ -H "Authorization: Bearer $ARK_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "from": "hello@yourdomain.com", "to": ["user@example.com"], "subject": "Your order has shipped!", "html": "<h1>Order Shipped</h1><p>Your order #1234 is on its way.</p>", "text": "Order Shipped\n\nYour order #1234 is on its way." }'
Always include both html and text versions. Some email clients only display plain text, and it improves deliverability.
Add a tag and metadata to categorize and track emails:
Python
Node.js
Ruby
Go
email = client.emails.send( from_="orders@yourdomain.com", to=["customer@example.com"], subject="Order Confirmation #1234", html="<p>Thank you for your order!</p>", tag="order_confirmation", metadata={ "order_id": "ord_1234", "customer_id": "cust_abc123", "campaign": "checkout_flow" })
const email = await client.emails.send({ from: 'orders@yourdomain.com', to: ['customer@example.com'], subject: 'Order Confirmation #1234', html: '<p>Thank you for your order!</p>', tag: 'order_confirmation', metadata: { order_id: 'ord_1234', customer_id: 'cust_abc123', campaign: 'checkout_flow', },});
email = client.emails.send_( from: "orders@yourdomain.com", to: ["customer@example.com"], subject: "Order Confirmation #1234", html: "<p>Thank you for your order!</p>", tag: "order_confirmation", metadata: { order_id: "ord_1234", customer_id: "cust_abc123", campaign: "checkout_flow" })
email, err := client.Emails.Send(ctx, ark.EmailSendParams{ From: "orders@yourdomain.com", To: []string{"customer@example.com"}, Subject: "Order Confirmation #1234", HTML: ark.String("<p>Thank you for your order!</p>"), Tag: ark.String("order_confirmation"), Metadata: map[string]string{ "order_id": "ord_1234", "customer_id": "cust_abc123", "campaign": "checkout_flow", },})
Metadata in Webhooks: When you include metadata with an email, it’s automatically returned in all webhook events for that message (MessageSent, MessageBounced, etc.). This makes it easy to correlate delivery events with your internal systems.
email = client.emails.send( from_="security@yourdomain.com", to=["user@example.com"], subject="Password Reset", html="<p>Click here to reset your password...</p>", track_opens=False, track_clicks=False)
const email = await client.emails.send({ from: 'security@yourdomain.com', to: ['user@example.com'], subject: 'Password Reset', html: '<p>Click here to reset your password...</p>', trackOpens: false, trackClicks: false,});
email = client.emails.send_( from: "security@yourdomain.com", to: ["user@example.com"], subject: "Password Reset", html: "<p>Click here to reset your password...</p>", track_opens: false, track_clicks: false)
email, err := client.Emails.Send(ctx, ark.EmailSendParams{ From: "security@yourdomain.com", To: []string{"user@example.com"}, Subject: "Password Reset", HTML: ark.String("<p>Click here to reset your password...</p>"), TrackOpens: ark.Bool(false), TrackClicks: ark.Bool(false),})