Skip to main content

Send an email

Beta

Being rolled out. The interface described here is the one of the next release: it may still change, and may not be enabled on your tenant yet.

E-mails are sent from templates you declare: no free-form messages.

Your tenant can send transactional e-mails (welcome, notification, confirmation) from its generated APIs and from the console. Three objects of the mail.stackngo.io group describe sending: a provider (the SMTP account), a sender (the From address) and a template (subject and body).

Prerequisites​

  • A session on your tenant (sng tenant use acme) and the mail:write right to declare, mail:send to send (managed policies readwrite or admin).
  • An SMTP account at your mail host (port 465 or 587, TLS) and its password, stored in a secret of your tenant.
  • Access to the DNS zone of the sending domain.

1. Declare the provider, the sender and the template​

mail.yml
apiVersion: mail.stackngo.io/v1alpha1
kind: MailProvider
metadata:
name: main
spec:
host: smtp.example.com
port: 587
tls:
mode: starttls
auth:
username: notifications@example.com
passwordSecretRef:
name: smtp-main
---
apiVersion: mail.stackngo.io/v1alpha1
kind: MailUser
metadata:
name: notifications
spec:
address: notifications@example.com
providerRef:
name: main
---
apiVersion: mail.stackngo.io/v1alpha1
kind: MailTemplate
metadata:
name: welcome
spec:
lang: fr
subject: "Bienvenue {{.Prenom}}"
text: "Bonjour {{.Prenom}}, votre compte est prêt."
variables:
- name: Prenom
example: Camille
sng apply mail.yml

You get the same result in the console, E-mails page: Providers, Templates and Senders tabs.

2. Verify the sending domain​

A sender only sends once its domain is verified. In the console, open the sender: the page lists the DNS records to publish, with their state.

CheckWhat is needed
OwnershipA TXT record shown by the console, unless the domain is already in a zone of your tenant
SPFA record that authorizes your provider
DMARCA _dmarc record (the console suggests a value)
DKIMYour provider's selectors, if declared in domainAuth

Publish them in your zone (see Records), then click Verify. The sender is ready when its Ready condition is True.

3. Send a test e-mail from the console​

On a ready sender, Send a test e-mail sends a trial message to an address of your choice. The Latest messages list shows each message's status (queued, sent, failed) and an error code if any. It never shows the message body.

4. Send from a generated API​

In the GeneratedAPI, designate the sender and the templates the API may use:

spec:
mail:
senderRef: notifications # name of a MailUser of your tenant
templates: [welcome] # names of MailTemplate objects of your tenant

The API only sends these templates from that sender. While the sender or a template is not ready, the GeneratedAPI stays Synced=False with reason MailNotReady.

A message gives the template, the sender, the recipients and the value of each variable:

{
"template": "welcome",
"from": "notifications",
"to": ["camille@example.com"],
"variables": {"Prenom": "Camille"}
}

The response says the message was accepted (queued). Sending twice with the same Idempotency-Key header produces one message.

Limits​

LimitValue
Recipients per message50
Messages per hour to the same address10
Provider ratelimits.perMinute (60 by default, 120 at most)
Providers per tenant5
Size of a variable value4 KiB

Beyond these, sending is refused with a rate_limited or quota_exceeded error and a delay before retrying.

Troubleshooting​

SymptomLikely cause
Sending refused, sender_not_readyThe domain is not verified or the provider is not Ready
Reachable=False, category authUsername or password refused by the SMTP server
Reachable=False, category tlsWrong port/mode pair (465 with implicit, 587 with starttls) or invalid certificate
template_invalidA variable is used but not declared, or the reverse: read the template's Valid condition
forbiddenThe mail:send right is missing on the sender or the template

Going further​