Documentation
Send email from Remix and React Router.
An action that reads the form, sends the message, and returns the result to the page.
Before you start
You need a verified sending domain (see Domains) and an API key (under API keys in the dashboard; it is shown once). Keep the key in an environment variable on your server, never in code that runs in a browser or an app.
Install
Add the client. Actions run on the server, so the key never reaches the browser.
The action
Remix and React Router v7 use the same shape. In React Router v7 import ActionFunctionArgs from react-router; in Remix v2 import it from @remix-run/node (or the runtime package you use).
On Cloudflare
On Cloudflare Workers there is no process.env: read the key from the context your adapter gives the action (context.cloudflare.env.MAILTRUSS_API_KEY) and set it with wrangler secret put.
Try it without sending real mail
Send to delivered@mailtruss.test first. It works before any domain is verified and reaches no real mailbox, so you can check your code and see the recorded timeline. Then try bounced@mailtruss.test to see what a bounce looks like. All the test addresses are listed under Sending.
See what happened
Open the message under Emails in the dashboard: it shows the recorded timeline, what each event proves, and a diagnosis if something went wrong. Or fetch it with GET /api/v1/emails/:id/events. To be told as it happens, add a webhook.
If it fails
API requests answer with an error name and message. The common ones:
403 invalid_api_keyor401 missing_api_key: the key is wrong, revoked or not sent. Send it asAuthorization: Bearer ms_live_….403 domain_not_verified: the from address is on a domain that is not verified. Publish the DNS records and re-check.422 validation_error: fix the field the message names. Nothing was sent and no quota was used.429 rate_limit_exceeded: back off for theRetry-Afterheader. See rate limits.
Problems that happen after a message is accepted (bounces, complaints) are explained under delivery errors.