Strapi

Strapi email with Hermaily

Strapi sends through its Email plugin, which uses a provider. With the Nodemailer provider pointed at Hermaily, the password resets and confirmations of Users & Permissions and the emails you send from your own code leave from your domain.

  • SMTP smtp.hermaily.com:587
  • Strapi 4 and 5
  • @strapi/provider-email-nodemailer

Before you start

Three things from Hermaily before the first message:

  1. An account. Create one (there is a free plan). New accounts are reviewed before they can send; you can set everything up in the meantime.
  2. A verified domain. In Domains, the assistant gives you the DKIM, SPF and DMARC records and checks they are published. You can only send from addresses on that domain or its subdomains.
  3. An API key for that domain, created in API keys. It starts with hm_ and is shown only once: keep it in your secrets manager or in the environment, never in the repository. The same key is the SMTP password; the username is apikey.

Configuration

Install the provider:

shell
npm install @strapi/provider-email-nodemailer

Configure it in config/plugins.js:

JavaScript · config/plugins.js
// config/plugins.js (or config/plugins.ts)
module.exports = ({ env }) => ({
  email: {
    config: {
      provider: "nodemailer",
      providerOptions: {
        host: env("SMTP_HOST", "smtp.hermaily.com"),
        port: env.int("SMTP_PORT", 587),
        secure: false,           // STARTTLS on 587; true for 465
        auth: {
          user: env("SMTP_USERNAME", "apikey"),
          pass: env("SMTP_PASSWORD"),
        },
      },
      settings: {
        defaultFrom: "hello@acme.example",
        defaultReplyTo: "support@acme.example",
      },
    },
  },
});

And the variables, in .env (or in your host's environment):

.env
# .env
SMTP_HOST=smtp.hermaily.com
SMTP_PORT=587
SMTP_USERNAME=apikey
SMTP_PASSWORD=hm_your_api_key

defaultFrom must be on your verified domain. The Users & Permissions plugin has its own sender in Settings → Users & Permissions plugin → Email templates: in each template, set Shipper email on your verified domain too.

Send a message

Restart Strapi and check it from the admin: the Email Configuration page under Settings has a test email field (Send test email). From your code:

JavaScript
// In a controller, service or lifecycle hook
await strapi.plugin("email").service("email").send({
  to: "lucia@example.com",
  subject: "Your order is on its way",
  text: "Hi Lucía, order 48213 has shipped.",
  html: "<p>Hi Lucía, order <b>48213</b> has shipped.</p>",
});

For a newsletter, add headers: { "X-Hermaily-Stream": "broadcast" } and send one message per recipient (paid plans).

Over HTTPS: the Mailgun provider

If you use the Mailgun provider, Hermaily accepts its request on the same path: change its url and the key. That way the request goes over HTTPS (port 443), useful if your host blocks SMTP. Details in migrate from Mailgun.

JavaScript · config/plugins.js
// npm install @strapi/provider-email-mailgun
email: {
  config: {
    provider: "mailgun",
    providerOptions: {
      key: env("HERMAILY_API_KEY"),
      domain: "acme.example",
      url: "https://api.hermaily.com",
    },
    settings: { defaultFrom: "hello@acme.example", defaultReplyTo: "support@acme.example" },
  },
},

Events and webhooks

Every message gets an id: over SMTP it comes in the server's reply to the message (250 2.0.0 Ok: queued as <id>). Accepted means queued, not delivered. To know what happened next:

  • Dashboard. Messages lists each message with its events: delivered, deferred, bounced, complaint, opened, clicked.
  • API. GET https://api.hermaily.com/v1/messages/{id} returns the current status and every event, oldest first (see looking up a message).
  • Webhooks. In Webhooks, add your URL (https and public) and the events you want. Hermaily makes one POST per event, signed with X-Hermaily-Signature: t=<unix>,v1=<hex>, where v1 is HMAC-SHA256(secret, t + "." + body) over the raw body. Answer any 2xx within 10 seconds; otherwise it is retried for about a day and a half. Delivery is at least once, so discard duplicates by the event id. The Test button sends a sample event to check your receiver.

Event types: send, delivery, delivery_delay, bounce, complaint, reject, rendering_failure, open, click and unsubscribe (opens and clicks only with tracking on). Permanent bounces, complaints and unsubscribes are suppressed automatically, so you do not need to keep your own list for that. Payload, fields and signature details are in the webhook documentation.

To receive them in Strapi, add a custom route whose controller verifies the signature over the raw body, as in the Node.js guide.

Troubleshooting

The errors you are most likely to see, with what they mean. The full list is in errors and limits.

535 5.7.8: authentication failed

The password must be the whole API key (hm_...), copied without spaces and not revoked. The username can be anything; use apikey. After many failed attempts from the same IP, logins are refused for a few minutes.

The connection hangs or times out

Your host blocks outgoing SMTP. Try port 465 with implicit TLS instead of 587. If both are closed, switch to the Mailgun provider pointed at Hermaily (see above), which goes over HTTPS.

550 5.7.1: the message is refused

The account cannot send right now (pending approval, paused, or new terms to accept), the key is restricted to the other stream, or the From address is not on the key's domain. Over the API this is 403 forbidden.

550 5.6.0: the message is rejected

Usually the From domain is not verified yet, there are more recipients than your plan allows (5 on Free, 50 on paid plans) or the message is too large. Over the API this is 422 validation, with the reason in the message.

451 4.7.1: try again later

The plan's per-minute limit or a new account's daily warm-up limit. It is temporary: retry later (over the API, 429 rate_limited). 552 5.3.4 means the monthly quota of the Free plan is used up (402 quota_exceeded).

Send your first message today

Create the account, verify your domain and paste the key. The free plan is enough to try it.

Create a free account