Charts in Email
End-to-end examples for embedding charts in HTML emails with Resend, Nodemailer, or any SMTP provider. Every example is copy-paste runnable.
How it works
Email clients load images with <img src="URL">. Chart-Output's GET endpoint renders and returns a chart image when a URL is requested — no JavaScript, no iframes. Just an image URL.
Because browsers and email clients cannot send Authorization headers with image requests, pass your API key as a ?key= query parameter. The key is then part of the image URL, so anyone who views the email source can read it. For emails that go to other people, render once with returnUrl: true and embed the hosted image URL, which does not contain your key.
Always use PNG for email. It has the broadest support across Gmail, Outlook, Apple Mail, and Yahoo. See the format compatibility table.
Simple embed (GET endpoint)
For charts with fewer than ~8 data points, a direct GET URL is the fastest path:
<img
src="https://www.chart-output.com/api/v1/render?key=pk_live_YOUR_KEY&type=bar&labels=Jan,Feb,Mar,Apr&data=12000,15000,18000,22000&format=png&width=600&height=300"
alt="Monthly revenue"
width="600"
height="300"
style="display:block;max-width:100%;height:auto;"
/>Keep URLs under 2000 characters. For complex specs, use POST + returnUrl (see below).
Resend
curl -X POST https://api.resend.com/emails \
-H "Authorization: Bearer re_YOUR_RESEND_KEY" \
-H "Content-Type: application/json" \
-d '{
"from": "reports@acme.com",
"to": ["user@example.com"],
"subject": "Your monthly report",
"html": "<img src=\"https://www.chart-output.com/api/v1/render?key=pk_live_YOUR_KEY&type=bar&labels=Jan,Feb,Mar,Apr&data=12000,15000,18000,22000&format=png&width=600&height=300\" alt=\"Revenue chart\" width=\"600\" height=\"300\" />"
}'import { Resend } from 'resend';
const resend = new Resend(process.env.RESEND_API_KEY);
const chartKey = process.env.CHART_OUTPUT_API_KEY;
// Build the chart URL — GET endpoint renders on demand
const chartUrl =
`https://www.chart-output.com/api/v1/render` +
`?key=${chartKey}` +
`&type=bar` +
`&labels=Jan,Feb,Mar,Apr` +
`&data=12000,15000,18000,22000` +
`&format=png` +
`&width=600&height=300`;
await resend.emails.send({
from: 'reports@acme.com',
to: 'user@example.com',
subject: 'Your monthly report',
html: `
<h1>Monthly Revenue</h1>
<img src="${chartUrl}" alt="Monthly revenue chart" width="600" height="300"
style="max-width:100%;height:auto;display:block;" />
<p>Revenue is up 14% from last month.</p>
`,
});import os, urllib.parse
import resend
resend.api_key = os.environ["RESEND_API_KEY"]
chart_key = os.environ["CHART_OUTPUT_API_KEY"]
params = urllib.parse.urlencode({
"key": chart_key,
"type": "bar",
"labels": "Jan,Feb,Mar,Apr",
"data": "12000,15000,18000,22000",
"format": "png",
"width": "600",
"height": "300",
})
chart_url = f"https://www.chart-output.com/api/v1/render?{params}"
resend.Emails.send({
"from": "reports@acme.com",
"to": ["user@example.com"],
"subject": "Your monthly report",
"html": f"""
<h1>Monthly Revenue</h1>
<img src="{chart_url}" alt="Monthly revenue chart"
width="600" height="300" style="max-width:100%;height:auto;display:block;" />
<p>Revenue is up 14% from last month.</p>
""",
})Nodemailer / SMTP
# Build the chart URL and use it in any SMTP tool
CHART_URL="https://www.chart-output.com/api/v1/render?key=pk_live_YOUR_KEY&type=line&labels=Jan,Feb,Mar,Apr&data=100,115,108,130&format=png&width=600&height=300"
echo "Embed: <img src=\"$CHART_URL\" />" import nodemailer from 'nodemailer';
const transport = nodemailer.createTransport({ /* your SMTP config */ });
const chartKey = process.env.CHART_OUTPUT_API_KEY;
const chartUrl =
'https://www.chart-output.com/api/v1/render' +
'?key=' + chartKey +
'&type=line&labels=Jan,Feb,Mar,Apr&data=100,115,108,130' +
'&format=png&width=600&height=300';
await transport.sendMail({
from: 'reports@acme.com',
to: 'user@example.com',
subject: 'Weekly stats',
html: `
<img src="${chartUrl}" alt="Weekly stats" width="600" height="300"
style="display:block;max-width:100%;height:auto;" />
`,
});import os, smtplib
from email.mime.text import MIMEText
chart_key = os.environ["CHART_OUTPUT_API_KEY"]
chart_url = (
"https://www.chart-output.com/api/v1/render"
f"?key={chart_key}"
"&type=line&labels=Jan,Feb,Mar,Apr&data=100,115,108,130"
"&format=png&width=600&height=300"
)
html = f"""
<img src="{chart_url}" alt="Weekly stats" width="600" height="300"
style="display:block;max-width:100%;height:auto;" />
"""
msg = MIMEText(html, "html")
msg["Subject"] = "Weekly stats"
msg["From"] = "reports@acme.com"
msg["To"] = "user@example.com"
with smtplib.SMTP("smtp.example.com", 587) as s:
s.starttls()
s.login("user", "password")
s.send_message(msg)POST + returnUrl (complex specs)
For specs that exceed 2000 characters, POST the spec with returnUrl: true. You get back a stable CDN URL to embed in your email:
# POST and capture the URL
RESPONSE=$(curl -s -X POST https://www.chart-output.com/api/v1/render \
-H "Authorization: Bearer pk_live_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"type":"bar","width":600,"height":300,"format":"png","returnUrl":true,"data":{"labels":["Jan","Feb","Mar"],"datasets":[{"data":[12000,15000,18000]}]}}')
URL=$(echo $RESPONSE | python3 -c "import sys,json; print(json.load(sys.stdin)['url'])")
echo "Embed URL: $URL"// Step 1: render and get a CDN URL
const res = await fetch('https://www.chart-output.com/api/v1/render', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.CHART_OUTPUT_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
type: 'bar',
width: 600,
height: 300,
format: 'png',
returnUrl: true,
data: {
labels: ['Jan', 'Feb', 'Mar', 'Apr'],
datasets: [{ label: 'Revenue', data: [12000, 15000, 18000, 22000] }],
},
}),
});
const { url } = await res.json();
// Step 2: embed the CDN URL in your email
const html = `<img src="${url}" alt="Revenue chart" width="600" height="300" />`;import os, json, urllib.request
resp = urllib.request.urlopen(urllib.request.Request(
"https://www.chart-output.com/api/v1/render",
data=json.dumps({
"type": "bar", "width": 600, "height": 300,
"format": "png", "returnUrl": True,
"data": {
"labels": ["Jan", "Feb", "Mar", "Apr"],
"datasets": [{"label": "Revenue", "data": [12000, 15000, 18000, 22000]}],
},
}).encode(),
headers={
"Authorization": f"Bearer {os.environ['CHART_OUTPUT_API_KEY']}",
"Content-Type": "application/json",
},
method="POST",
))
url = json.loads(resp.read())["url"]
# Embed url in your email HTMLFull card in email
Use padding: "email" to apply the email-optimized layout padding preset. Render at scale: 2 for retina output, with logical width/height attributes on the <img> tag.
{
"type": "line",
"brandKitId": "obsidian",
"width": 600,
"height": 360,
"format": "png",
"scale": 2,
"padding": "email",
"backgroundColor": "#0d1117",
"borderRadius": 12,
"border": { "color": "rgba(255,255,255,0.08)", "width": 1 },
"header": {
"eyebrow": "MONTHLY REPORT",
"title": "$22,000",
"subtitle": "↑ 22% from last month"
},
"data": {
"labels": ["Jan", "Feb", "Mar", "Apr"],
"datasets": [{
"label": "Revenue",
"data": [12000, 15000, 18000, 22000],
"borderColor": "#6ee7b7",
"backgroundColor": "rgba(110,231,183,0.07)",
"fill": true,
"tension": 0.4,
"borderWidth": 2,
"pointRadius": 0
}]
},
"footer": {
"left": "acme.com",
"right": "April 2026",
"borderTop": true
}
}POST this spec with returnUrl: true to get a CDN URL, then embed it with <img src="URL" width="600" height="360" />.
Troubleshooting
| Symptom | Fix |
|---|---|
| Image blocked on first open | Normal — email clients block images by default. Users click "Display images" once, then see them in all future emails. |
| Broken image in Outlook desktop | Check that your URL uses HTTPS. Verify the URL works in a browser before sending. |
| URL too long (> 2000 chars) | Use POST + returnUrl for complex specs instead of GET query params. |
| Distorted chart (labels/data mismatch) | Verify labels and data arrays have the same length. Test the URL directly in a browser. |
| 401 error in image | You cannot use Authorization headers in <img> tags. Use ?key= in the URL instead. |
Related walkthroughs
Chart.js in email
Render a Chart.js config as a static PNG that shows in Gmail, Outlook and Apple Mail.
Convert Chart.js to an image
Export a Chart.js config as PNG, SVG, WebP or PDF for email, reports and pipelines.
Add a chart to an n8n workflow
Google Sheets rows to a chart image in Slack or email, with one Code node and one HTTP Request node.