Hoppa till innehållet

Tools

SMTP submission

Use SMTP when a system cannot call an HTTP API, such as an ERP or a printer. A message sent over SMTP goes through the same checks as an API send. It appears in the same log, gets the same events and counts against the same limits.

To move a system that signs in to a Microsoft 365 mailbox with a password, follow Move from Microsoft 365.

Connect

SettingValue
Hostsmtp.sendora.se
Port465 with TLS from the start, or 587 with STARTTLS
User name and passwordA server key, sk_… or a test server’s sk_test_…, as both
AuthenticationPLAIN or LOGIN, once TLS is on

The From address must be on one of the server’s verified domains. The message limits apply as they do over the API, with To, Cc and Bcc counted together.

import nodemailer from 'nodemailer';

/** Sends one message over SMTP with a server's API token as both user name and password. */
export async function sendOverSmtp(
  token: string,
): Promise<string> {
  const transport = nodemailer.createTransport({
    host: 'smtp.sendora.se',
    port: 587,
    secure: false,
    requireTLS: true,
    auth: { user: token, pass: token },
  });
  const info = await transport.sendMail({
    from: '"Example AB" <no-reply@example.se>',
    to: 'anna@example.com',
    subject: 'Your account is ready',
    text: 'Hi Anna, your account at Example is ready.',
    headers: {
      'X-Sendora-Tag': 'welcome',
      'X-Sendora-Metadata-Customer': '4711',
    },
  });
  return info.response; // "250 2.0.0 OK: queued as <messageId>"
}
import smtplib
import ssl
from email.message import EmailMessage


# Sends one message over SMTP with a server's API
# token as both user name and password.
def send_over_smtp(token: str) -> None:
    message = EmailMessage()
    message["From"] = "Example AB <no-reply@example.se>"
    message["To"] = "anna@example.com"
    message["Subject"] = "Your account is ready"
    message["X-Sendora-Tag"] = "welcome"
    message["X-Sendora-Metadata-Customer"] = "4711"
    message.set_content(
        "Hi Anna, your account at Example is ready."
    )

    # Without a context of its own, starttls() would
    # accept any certificate, and without a timeout
    # smtplib waits forever on a stalled connection.
    context = ssl.create_default_context()
    with smtplib.SMTP(
        "smtp.sendora.se", 587, timeout=30
    ) as smtp:
        smtp.starttls(context=context)
        smtp.login(token, token)
        smtp.send_message(message)
<?php

use Symfony\Component\Mailer\Header\MetadataHeader;
use Symfony\Component\Mailer\Header\TagHeader;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mailer\Transport;
use Symfony\Component\Mailer\Transport\TransportInterface;
use Symfony\Component\Mime\Email;

// Sendora's SMTP submission, with a server's API token
// as both user name and password. smtps:// starts TLS
// before the token goes over.
function sendoraSmtp(string $token): TransportInterface
{
    return Transport::fromDsn(
        "smtps://{$token}:{$token}@smtp.sendora.se:465",
    );
}

// Give it new Mailer(sendoraSmtp($token)), or the
// MailerInterface that Symfony's framework injects.
function sendWelcome(MailerInterface $mailer): void
{
    $email = (new Email())
        ->from('Example AB <no-reply@example.se>')
        ->to('anna@example.com')
        ->subject('Your account is ready')
        ->text(
            'Hi Anna, your account at Example is ready.',
        );
    $email->getHeaders()
        ->add(new TagHeader('welcome'))
        ->add(new MetadataHeader('Customer', '4711'));

    $mailer->send($email);
}
import jakarta.mail.Message;
import jakarta.mail.MessagingException;
import jakarta.mail.Session;
import jakarta.mail.Transport;
import jakarta.mail.internet.MimeMessage;
import java.util.Properties;

// Jakarta Mail, with org.eclipse.angus:angus-mail as
// the dependency.
class SendOverSmtp {
  public static void main(String[] args)
      throws MessagingException {
    MimeMessage message = new MimeMessage(sendoraSmtp());
    message.setFrom("Example AB <no-reply@example.se>");
    message.setRecipients(
        Message.RecipientType.TO, "anna@example.com");
    message.setSubject("Your account is ready");
    message.setText(
        "Hi Anna, your account at Example is ready.");
    message.setHeader("X-Sendora-Tag", "welcome");
    message.setHeader(
        "X-Sendora-Metadata-Customer", "4711");

    // The server key is both user name and password.
    String token = System.getenv("SENDORA_API_TOKEN");
    Transport.send(message, token, token);
  }

  // Sendora's SMTP submission, on port 465 with TLS from
  // the start, so the key never goes over in the clear.
  static Session sendoraSmtp() {
    Properties settings = new Properties();
    settings.setProperty(
        "mail.smtp.host", "smtp.sendora.se");
    settings.setProperty("mail.smtp.port", "465");
    settings.setProperty("mail.smtp.ssl.enable", "true");
    settings.setProperty("mail.smtp.auth", "true");
    // Before Angus Mail 1.1, Jakarta Mail skips the check
    // of the certificate's name.
    settings.setProperty(
        "mail.smtp.ssl.checkserveridentity", "true");
    // Without these, it waits forever on a stalled
    // connection.
    settings.setProperty(
        "mail.smtp.connectiontimeout", "30000");
    settings.setProperty("mail.smtp.timeout", "30000");
    settings.setProperty(
        "mail.smtp.writetimeout", "30000");
    return Session.getInstance(settings);
  }
}

Sendora delivers only to the envelope recipients, the addresses your client gives in RCPT TO. The To and Cc headers decide how each of them is shown, and an envelope recipient that neither header names is sent as Bcc. An address that only a header names gets nothing.

Send from Nodemailer

Nodemailer sends through a transport that you create once and use for every message. Give it the server key as both user name and password, on port 465 with TLS from the start. Nodemailer then checks the server’s certificate and its name. The From address must be on a verified domain.

import nodemailer from 'nodemailer';

const key = process.env.SENDORA_API_TOKEN;

// Port 465 has TLS from the start, so the key never goes
// over in the clear, and Nodemailer checks the server's
// certificate and its name.
export const transport = nodemailer.createTransport({
  host: 'smtp.sendora.se',
  port: 465,
  secure: true,
  auth: { user: key, pass: key },
});

export async function sendWelcome() {
  const info = await transport.sendMail({
    from: '"Example AB" <no-reply@example.se>',
    to: 'anna@example.com',
    subject: 'Your account is ready',
    text: 'Hi Anna, your account at Example is ready.',
    headers: {
      'X-Sendora-Tag': 'welcome',
      'X-Sendora-Metadata-Customer': '4711',
    },
  });
  // Sendora replaces the Message-ID in info.messageId.
  // Its own id, which the log and the webhooks use, is
  // in the reply.
  const id = /(?:queued|accepted) as ([\w-]+)/;
  return id.exec(info.response)?.[1];
}

To use port 587 instead, set secure: false and requireTLS: true. Without STARTTLS, Nodemailer then fails rather than send the key in the clear.

Sendora writes its own Message-ID, so info.messageId is not the id that the log and the webhooks use. Sendora’s id for the message is in the reply, info.response, after queued as. A test server’s reply has it after accepted as.

If Sendora refuses the message, sendMail throws an error whose responseCode is the reply’s code, which SMTP replies lists. Past a message’s recipient limit, Sendora refuses each extra recipient. Nodemailer then sends to the rest and lists the refused ones in info.rejected.

Send from Django

Django sends over SMTP out of the box and checks the server’s certificate when it starts TLS. In settings.py, use the server key from the environment as both user name and password. DEFAULT_FROM_EMAIL must be on a verified domain, and so must SERVER_EMAIL, the address Django sends its error mail from.

import os

# In settings.py, for Django's SMTP backend, its
# default: the server key as user name and password.
EMAIL_HOST = "smtp.sendora.se"
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = os.environ["SENDORA_API_TOKEN"]
EMAIL_HOST_PASSWORD = os.environ["SENDORA_API_TOKEN"]
EMAIL_TIMEOUT = 30
DEFAULT_FROM_EMAIL = "Example AB <no-reply@example.se>"
SERVER_EMAIL = DEFAULT_FROM_EMAIL

Django 6.1 replaces the EMAIL_* settings with MAILERS and refuses to start with both. On 6.1, put the same values in MAILERS["default"]["OPTIONS"] as host, port, use_tls, username, password and timeout. DEFAULT_FROM_EMAIL and SERVER_EMAIL stay as they are.

To send through the API instead, with each message’s id in hand, use the Python SDK, as the Django guide shows.

Send from Laravel or Symfony

Laravel and Symfony send over SMTP with their own mailers. Use the server key as both user name and password, on port 465 with TLS from the start. Set SENDORA_API_TOKEN to the key in .env, and the settings below read it. The From address must be on a verified domain.

In Laravel, set the smtp mailer in .env:

MAIL_MAILER=smtp
MAIL_SCHEME=smtps
MAIL_HOST=smtp.sendora.se
MAIL_PORT=465
MAIL_USERNAME="${SENDORA_API_TOKEN}"
MAIL_PASSWORD="${SENDORA_API_TOKEN}"
MAIL_FROM_ADDRESS=no-reply@example.se

A mailable’s tags and metadata become the message’s tag and metadata, as the next section says. Give a mailable one tag, since a message with two different tags is refused.

To send through the API instead, with each message’s id in hand, use the Laravel package, as the Laravel guide shows.

In Symfony, set MAILER_DSN in .env:

MAILER_DSN=smtps://${SENDORA_API_TOKEN}:${SENDORA_API_TOKEN}@smtp.sendora.se:465

Add the tag with Symfony’s TagHeader and each metadata entry with its MetadataHeader. To send through the API instead, use the PHP SDK’s transport, as the Symfony guide shows.

Send from Spring Boot

Spring Boot sends over SMTP once spring-boot-starter-mail is a dependency. Put the settings below in application.properties, and set SENDORA_API_TOKEN to the server key in the app’s environment. The settings use the key as both user name and password, on port 465 with TLS from the start. Spring Boot then checks the server’s certificate and its name. Jakarta Mail waits forever on a stalled connection by default, so the last three lines set its timeouts in milliseconds.

spring.mail.host=smtp.sendora.se
spring.mail.port=465
spring.mail.ssl.enabled=true
spring.mail.username=${SENDORA_API_TOKEN}
spring.mail.password=${SENDORA_API_TOKEN}
spring.mail.properties.mail.smtp.connectiontimeout=30000
spring.mail.properties.mail.smtp.timeout=30000
spring.mail.properties.mail.smtp.writetimeout=30000

A SimpleMailMessage carries no headers. To set the tag and metadata, send a MimeMessage through the JavaMailSender that Spring Boot builds from these settings. The next section lists the headers. The From address must be on a verified domain.

mailSender.send(mime -> {
    var mail = new MimeMessageHelper(mime, "UTF-8");
    mail.setFrom("Example AB <no-reply@example.se>");
    mail.setTo("anna@example.com");
    mail.setSubject("Your account is ready");
    mail.setText(
            "Hi Anna, your account at Example is ready.");
    mime.setHeader("X-Sendora-Tag", "welcome");
    mime.setHeader("X-Sendora-Metadata-Customer", "4711");
});

Set the stream, tag, metadata and tracking

HeaderSets
X-Sendora-StreamThe stream the message goes on, by its id
X-Sendora-TagThe message’s tag
X-Sendora-Metadata-<key>One metadata entry: X-Sendora-Metadata-Customer: 4711 sets { "customer": "4711" }
X-Sendora-Track-OpensWhether the message’s opens are tracked, as true or false
X-Sendora-Track-LinksWhether the message’s links are tracked, as true or false

Without X-Sendora-Stream, the message goes on the server’s default transactional stream.

Sendora also reads X-Tag and X-Metadata-<key>, which Laravel’s and Symfony’s mailers write for a message’s tags and metadata. X-Sendora-Tag and X-Sendora-Metadata-<key> win over them. A message has one tag: the same tag given twice counts once, and two different tags are refused with 550 5.6.0. A metadata key is lowercased, since a header’s name ignores case.

The two tracking headers override the stream’s switches for this message, as trackOpens and trackLinks do over the API. Without them, the stream decides. Each is true or false in any case, and the same value given twice counts once. Another value, an empty one, or both true and false are refused with 550 5.6.0. A true is refused with 550 5.7.1 until an administrator has switched tracking on for a stream in the dashboard. It is also refused where Sendora has withdrawn tracking from the account.

Attachments are ordinary MIME parts. Sendora also keeps Reply-To, In-Reply-To, References, List-Unsubscribe, List-Unsubscribe-Post and your own X- headers, but not the headers that this section names, which it reads. A References header longer than 998 characters keeps its first id and its latest ones. Sendora drops other headers, such as Message-ID, Received or DKIM-Signature, and writes its own. The API refuses these headers instead of dropping them.

The subject, a display name, the tag, a metadata value and your own X- headers may hold text outside ASCII. Write it in UTF-8 as it is, or as an encoded word in any character set. Raw bytes that are not UTF-8 become U+FFFD, the replacement character. An address must be ASCII, with an internationalised domain in its xn-- form.

SMTP replies

Sendora accepts or refuses a message before the session ends. A 250 means the message is stored and already in the log, and Sendora never refuses it after that. Delivery outcomes, such as a bounce, arrive later as events. A 5xx reply means a retry will not help. A 4xx reply means a retry may succeed.

ReplyWhen
250 2.0.0 OK: queued as <messageId>Accepted. The id is the one the log and the webhooks use.
530 5.7.0The client sent a message without authenticating.
535 5.7.8The key is wrong, revoked or an account key, or the user name and password differ.
550 5.7.1The From domain is not verified, or the account is paused. On a live server, the account is not approved, or it waits for a payment, as Errors describes. It also covers a stream in X-Sendora-Stream that is unknown, archived, paused or inbound, and a tracking header’s true that the account cannot use.
550 5.1.1A recipient is suppressed, or a live server was given an address at simulator.sendora.se. The text lists the addresses.
550 5.6.0The API would refuse the message as invalid, or it breaks the rules of a broadcast stream. The text gives the reasons.
552 5.3.4The message is over the size limit.
452 4.5.3The message has more recipients than a message may have. Split them over several messages.
451 4.7.0The per-minute limit, the monthly cap or the daily cap that an account can have is reached. The text says when to try again.
451 4.3.2Sending is disabled for everyone for the moment.
451 4.3.0A temporary failure on Sendora’s side.