In this article
Transactional SDKs
The official Mail Blaze transactional SDKs let you send order confirmations, password resets, and other system email from your application without building the HTTP requests yourself. You pass normal strings and files. Each SDK encodes the payload, sets the correct headers, and maps API errors to typed exceptions.
These packages cover transactional email only. For lists, subscribers, templates, campaigns, and reporting, use the REST API Documentation.
Create Your API Key
- Log into your Mail Blaze account
- Click on your account name > API Keys
- On the API KEYS page, click the GENERATE NEW button. A new API key should appear.
- Click on the API key
- Copy the Public key. This is the key you pass into the SDK
Store the key in an environment variable such as MAILBLAZE_API_KEY. Do not commit it to source control. The SDKs send it as the raw Authorization header (not Bearer, and never in the URL).
The from address must use a domain you have verified in Mail Blaze. An unverified domain returns error code 150.010.
Available SDKs
| Language | Package | Install |
|---|---|---|
| PHP | mailblaze/transactional | composer require mailblaze/transactional |
| Node.js | @mailblaze/transactional | npm install @mailblaze/transactional |
| Python | mailblaze-transactional | pip install mailblaze-transactional |
Shared essentials
All three SDKs talk to the same Control API:
https://control.mailblaze.com/api
Endpoints used by the SDKs:
POST /transactional
GET /transactional
GET /transactional/{email_uid}
GET /transactional/attachments/{email_uid}
| Topic | Detail |
|---|---|
| Content | Provide either HTML (body) or a template_id. These are mutually exclusive. |
| Encoding | HTML, plain text, and attachment bytes are base64-encoded by the SDK. You pass normal strings and files. |
| Attachments | Up to 10 MiB of base64 data per attachment (about 7.5 MiB of file bytes). The API detects the content type from the file bytes. |
| Merge tags | Names must match [A-Z0-9_]. Use MAILBLAZE_PREHEADER for the preheader. Every tag used in the template must be supplied. |
| Scheduling | Pass a future time to hold the email until that moment. Omit it, or pass a time in the past, to send immediately. |
| Retries | Sends are never retried automatically (there is no idempotency key). Safe GET requests may be retried a small number of times. |
| Bcc | Bcc recipients receive the email and are not shown to other recipients. |
PHP SDK
Package: mailblaze/transactional
Requirements: PHP 8.3 or newer, plus an HTTP client such as Symfony HTTP Client or Guzzle, and PSR-17 factories (for example nyholm/psr7).
Install
composer require mailblaze/transactional symfony/http-client nyholm/psr7
Send an email
use MailBlaze\Transactional\Client;
use MailBlaze\Transactional\Email;
$client = Client::create((string) getenv('MAILBLAZE_API_KEY'));
$result = $client->emails()->send(
Email::make()
->to('[email protected]', 'Jane Doe')
->from('[email protected]', 'Acme')
->subject('Your receipt')
->html('<p>Thanks for your order.</p>')
->text('Thanks for your order.')
);
$uid = $result->emailUid();
to(), from(), and subject() are required. Either html() or templateId() is required. text() is optional with html().
Email is immutable. Each method returns a new Email, so you can reuse a shared base:
$base = Email::make()->from('[email protected]', 'Acme')->subject('Your receipt');
$forJane = $base->to('[email protected]', 'Jane Doe')->html('<p>Hi Jane</p>');
$forJohn = $base->to('[email protected]', 'John Doe')->html('<p>Hi John</p>');
Send a template
$result = $client->emails()->send(
Email::make()
->to('[email protected]', 'Jane Doe')
->from('[email protected]', 'Acme')
->subject('Your order')
->templateId('ab123456-1234-1234-1234-123456789abc')
->mergeTags(['NAME' => 'Jane', 'ORDER_ID' => '1001'])
);
Attachments and scheduling
use MailBlaze\Transactional\Attachment;
$email = Email::make()
->to('[email protected]', 'Jane Doe')
->from('[email protected]', 'Acme')
->subject('Invoice')
->html('<p>Invoice attached.</p>')
->attach(Attachment::fromPath('/tmp/invoice.pdf'));
List, fetch, and attachments
$page = $client->emails()->list(page: 1, perPage: 10);
$email = $client->emails()->get($uid);
$files = $client->emails()->attachments($uid);
perPage is clamped to 10–50 (default 10). page must be at least 1.
Common PHP errors
| Exception | When |
|---|---|
| AuthenticationException | Sending is turned off (150.001), or the API key is rejected |
| QuotaException | Insufficient credits (150.015) |
| DomainNotVerifiedException | From-domain is not verified (150.010) |
| ValidationException | Invalid input, or API validation codes such as 150.002–150.006, 150.011, 150.012, 150.014 |
| NotFoundException | Email or template not found (150.009, 150.013) |
| SendFailedException | Send failed (150.007, 150.016) |
| UnconfirmedSendException | HTTP 2xx on send, but the response body could not be read. Check list() or get() before sending again |
Full reference: Packagist README
Node.js SDK
Package: @mailblaze/transactional
Requirements: Node.js ^22.14.0, ^24.0.0, or ^26.0.0. The package is ESM. On supported Node versions, require() can also load it.
Install
npm install @mailblaze/transactional
Send an email
import { MailBlaze } from '@mailblaze/transactional';
const apiKey = process.env.MAILBLAZE_API_KEY;
if (apiKey === undefined || apiKey === '') {
throw new Error('Set MAILBLAZE_API_KEY');
}
const mailblaze = new MailBlaze({ apiKey });
const sent = await mailblaze.send({
to: { email: '[email protected]', name: 'Jane Doe' },
from: { email: '[email protected]', name: 'Acme' },
subject: 'Your receipt',
html: '<p>Thanks for your order.</p>',
text: 'Thanks for your order.',
});
console.log(sent.emailUid);
CommonJS:
const { MailBlaze } = require('@mailblaze/transactional');
Send a template
const sent = await mailblaze.send({
to: { email: '[email protected]', name: 'Jane Doe' },
from: { email: '[email protected]', name: 'Acme' },
subject: 'Your order',
templateId: 'ab123456-1234-1234-1234-123456789abc',
mergeTags: { NAME: 'Jane', ORDER_ID: '1001', MAILBLAZE_PREHEADER: 'Your order' },
});
Attachments
Attachments are file bytes, not a URL or path. To load a local file in Node.js:
import { attachmentFromPath } from '@mailblaze/transactional';
await mailblaze.send({
to: { email: '[email protected]', name: 'Jane Doe' },
from: { email: '[email protected]', name: 'Acme' },
subject: 'Invoice',
html: '<p>Invoice attached.</p>',
attachments: [await attachmentFromPath('/tmp/invoice.pdf')],
});
Or pass bytes directly:
attachments: [{ filename: 'invoice.pdf', data: pdfBytes }],
List, fetch, and attachments
const page = await mailblaze.list({ page: 1, perPage: 10 });
const email = await mailblaze.get(sent.emailUid);
const files = await mailblaze.attachments(sent.emailUid);
Common Node.js errors
| Error | When |
|---|---|
| AuthenticationError | Sending is turned off (150.001), or the API key is rejected |
| QuotaError | Insufficient credits (150.015) |
| DomainNotVerifiedError | From-domain is not verified (150.010) |
| ValidationError | Invalid input, or API validation codes such as 150.002–150.006, 150.011, 150.012, 150.014 |
| NotFoundError | Email or template not found (150.009, 150.013) |
| SendFailedError | Send failed (150.007, 150.016) |
| UnconfirmedSendError | HTTP 2xx on send, but the response body could not be read. Check list or get before sending again |
Full reference: npm package README
Python SDK
Package: mailblaze-transactional
Requirements: Python 3.11 or newer. No runtime dependencies. Fully typed (py.typed).
Install
pip install mailblaze-transactional
Send an email
import os
from mailblaze_transactional import Client, Email
with Client(os.environ["MAILBLAZE_API_KEY"]) as client:
result = client.emails.send(
Email()
.to("[email protected]", "Jane Doe")
.from_("[email protected]", "Acme")
.subject("Your receipt")
.html("<p>Thanks for your order.</p>")
.text("Thanks for your order.")
)
print(result.email_uid)
Use from_() (with an underscore) because from is a Python keyword. to(), from_(), and subject() are required. Exactly one of html() or template_id() is required.
Email is immutable. Always keep the returned value:
base = Email().from_("[email protected]", "Acme").subject("Your receipt")
for_jane = base.to("[email protected]", "Jane Doe").html("<p>Hi Jane</p>")
for_john = base.to("[email protected]", "John Doe").html("<p>Hi John</p>")
Send a template
result = client.emails.send(
Email()
.to("[email protected]", "Jane Doe")
.from_("[email protected]", "Acme")
.subject("Your order")
.template_id("ab123456-1234-1234-1234-123456789abc")
.merge_tags({"NAME": "Jane", "ORDER_ID": 1001})
)
Attachments and scheduling
from datetime import datetime, timedelta, timezone
from mailblaze_transactional import Attachment
email = (
Email()
.to("[email protected]", "Jane Doe")
.from_("[email protected]", "Acme")
.subject("Invoice")
.html("<p>Invoice attached.</p>")
.bcc("[email protected]")
.category("invoices")
.send_at(datetime.now(timezone.utc) + timedelta(hours=1))
.attach(Attachment.from_path("/tmp/invoice.pdf"))
)
send_at() requires a timezone-aware datetime. Naive datetimes are rejected.
List, fetch, and attachments
page = client.emails.list(page=1, per_page=10)
for summary in page.records:
print(summary.email_uid, summary.status)
record = client.emails.get(result.email_uid)
print(record.subject, record.plain_text)
for file in client.emails.attachments(result.email_uid):
data = file.content() # bytes
Reuse one client, and close it with a context manager or client.close().
Common Python errors
| Exception | When |
|---|---|
| AuthenticationError | Sending is turned off (150.001), or the API key is rejected |
| QuotaError | Insufficient credits (150.015) |
| DomainNotVerifiedError | From-domain is not verified (150.010) |
| ValidationError | Invalid input, or API validation codes such as 150.002–150.006, 150.011, 150.012, 150.014 |
| NotFoundError | Email or template not found (150.009, 150.013) |
| SendFailedError | Send failed (150.007, 150.016) |
| UnconfirmedSendError | HTTP 2xx on send, but the response body could not be read. Check list() or get() before sending again |
Full reference: PyPI project page
Transactional error codes
These codes may appear in SDK exceptions and in direct API responses:
| Code | Description |
|---|---|
| 150.001 | Transactional sending is turned off for the account |
| 150.002 | Email body is not valid base64 |
| 150.003 | Plain text is not valid base64 |
| 150.004 | Attachment data is not valid base64 |
| 150.005 | Attachment exceeds the 10 MiB encoded size limit |
| 150.006 | The send-at datetime is not valid |
| 150.007 | The transactional email was not sent |
| 150.008 | Failed to get the list of transactional emails |
| 150.009 | No transactional email found for the requested unique ID |
| 150.010 | The from-domain is not verified |
| 150.011 | The JSON body is invalid |
| 150.012 | Provide either body or template_id (exactly one is required; they cannot be combined) |
| 150.013 | The template was not found |
| 150.014 | A template merge tag is missing |
| 150.015 | The account does not have enough credits |
| 150.016 | The transactional email was not sent |
SMTP
The SDKs use the HTTP API. They do not speak SMTP.
If you prefer SMTP, Mail Blaze provides:
Host: smtp.mailblaze.net
Port: 587
Encryption: STARTTLS
Authenticate with your customer API key. Contact Mail Blaze support if you need the current SMTP username and login method for your account.
Related documentation
- API Documentation — full REST reference for lists, subscribers, templates, campaigns, transactional email, and reporting
- Transactional email — product overview
- Interactive API tool: https://control.mailblaze.com/api/docs
Package pages:
Still haven't found what you are looking for?
Book a demo with us and see Mail Blaze in action, or reach out to our support team for expert assistance. We're here to help you every step of the way!
Still haven't found what you are looking for?
Still haven't found what you are looking for?
Book a demo with us and see Mail Blaze in action, or reach out to our support team for expert assistance. We're here to help you every step of the way!
Book a demo with us and see Mail Blaze in action, or reach out to our support team for expert assistance. We're here to help you every step of the way!