Skip to content
OnCharge.io
View as Markdown
Developer docs

SMTP relay

Send through OnCharge from anything that speaks SMTP: a store platform, a CMS plugin, a help desk, or an app whose mail library you don't want to replace. Mail sent over SMTP goes through the same checks, logs, suppressions and webhooks as mail sent with the API.

Settings#

SettingValue
Hostsmtp.oncharge.io
Port587 with STARTTLS, or 465 with TLS from the start
Usernameoncharge
PasswordA messaging API key (oc_msg_live_…) with the sending or full scope
EncryptionRequired. Plain, unencrypted connections are refused.

Create a key for each app under Email & SMS → API keys, with the sending scope and, if you like, limited to one domain. Then a leaked key can only send, and only from that domain, and you can revoke it without touching your other apps.

The From address must be on a verified domain.

Node.js (Nodemailer)#

mailer.mjs
import nodemailer from 'nodemailer';

const transport = nodemailer.createTransport({
  host: 'smtp.oncharge.io',
  port: 587,
  secure: false, // STARTTLS on 587; use port 465 with secure: true for TLS from the start
  requireTLS: true,
  auth: { user: 'oncharge', pass: process.env.ONCHARGE_MESSAGING_KEY },
});

await transport.sendMail({
  from: 'Example Store <orders@example.com>',
  to: 'shopper@example.net',
  subject: 'Your order #1001 is confirmed',
  text: 'Thanks for your order.',
  html: '<p>Thanks for your order.</p>',
});

PHP (PHPMailer)#

mailer.php
<?php
use PHPMailer\PHPMailer\PHPMailer;

$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'smtp.oncharge.io';
$mail->Port = 587;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->SMTPAuth = true;
$mail->Username = 'oncharge';
$mail->Password = getenv('ONCHARGE_MESSAGING_KEY');

$mail->setFrom('orders@example.com', 'Example Store');
$mail->addAddress('shopper@example.net');
$mail->Subject = 'Your order #1001 is confirmed';
$mail->isHTML(true);
$mail->Body = '<p>Thanks for your order.</p>';
$mail->AltBody = 'Thanks for your order.';
$mail->send();

Store platforms and plugins#

Most platforms have an "SMTP" or "custom mail server" setting, or a plugin that adds one. Enter the settings above. For WordPress and WooCommerce, any SMTP plugin works: choose "Other SMTP", host smtp.oncharge.io, port 587, TLS, authentication on, username oncharge, and your key as the password.

Limits#

SMTP has the same limits as the API: up to 50 recipients per message and 40 MB per message. See Limits & errors. The API has features SMTP does not, such as idempotency keys, scheduled sends, batches and templates.