Create an email provider
Answer an email API SendMock does not ship, from its docs to a working provider, step by step.
Try it in the demo.
SendMock ships SendGrid, Mailgun, Postmark, Resend, Amazon SES and Brevo. Any other email API can be added without code, because a provider is a definition: the requests it answers, where each part of the email is read from, and what it answers.
This walkthrough adds Mailjet, whose send API is POST /v3.1/send with a JSON body. Swap in your provider's names and fields as you go.
The field names below (
Messages,TextPart,MessageID, ...) come from Mailjet's API docs. Use the ones in your provider's docs.
Before you start: read the provider's docs for
- The send request: method, path and body format (JSON, form or multipart).
- Where each part is: sender, recipients, subject, text and HTML.
- The answers: the success body (with the message id your app reads) and the error body.
- The credentials your app sends (API key and secret).
1. Add the provider
- Open Mail > Providers and press Add provider.
- Set Name to
Mailjet; the Key becomesmailjet. Leave Start from on Blank and press Add provider. The provider sheet opens.
2. General
- Set Host to
api.mailjet.com. - Press Add credential twice:
api_key, andsecret_keymarked Secret.
3. Requests
-
Change Request 1 path to
/v3.1/send. Keep POST and JSON. -
Under Field mapping, press Map a part for each part and set its source:
Part Source from Messages[0].From.Emailto Messages[0].To[*].Emailsubject Messages[0].Subjecttext Messages[0].TextParthtml Messages[0].HTMLPart -
Under Checks on a send, press Add check:
to, Required, Missing field.
4. Responses
-
Set Message id to
{{ random_hex(16) }}. -
Set the Success response body to:
{"Messages": [{"Status": "success", "To": [{"Email": "{{ message.to }}", "MessageID": "{{ message.provider_id }}"}]}]} -
Press Add an error response and set its body to:
{"ErrorMessage": "{{ error.reason }}", "StatusCode": 400}
5. Check the preview
Open Preview. The sample send is built from your field mapping: the Stored message shows [email protected] as recipient, and the Response is 200 with your body. Clear the sample body to {} and the answer becomes your error response.
6. Save and connect your app
- Press Save provider. Mailjet is listed as Custom.
- Open Try it and point Mailjet's SDK at the base URL it shows.
To share it with your team, export the seed file in Settings > Seed: custom providers are saved with their secrets as ${ENV} references.