Skip to main content

Setup

You will need a MailerSend account with a verified sending domain.
1

Verify Your Domain

In MailerSend, add your domain and complete DNS verification.
2

Generate an API Token

Click “Manage” on your domain and generate an API token.
3

Configure in Courier

In Courier, navigate to the MailerSend Integration page. Enter your API token and From Address, then click “Save.”

Profile Requirements

To deliver a message to a recipient over MailerSend, Courier must be provided the recipient’s email address. This value should be included in the recipient profile as email.
{
  "message": {
    "to": {
      "email": "alice@acme.com"
    }
    // ... rest of message definition
  }
}

Overrides

You can override any of the fields supported by MailerSend’s /v1/email endpoint. Overrides are useful when a field is not yet supported by Courier or you want to replace a value that Courier generates. Config override example:
{
  "message": {
    "template": "NOTIFICATION_TEMPLATE_ID",
    "to": {
      "email": "alice@acme.com"
    },
    "providers": {
      "mailersend": {
        "override": {
          "config": {
            "apiKey": "<your override API key>",
            "fromAddress": "alternate-sender@yourdomain.com"
          }
        }
      }
    }
  }
}

Attachments

To include an attachment, add an attachments array in the override. File content must be base64-encoded.
{
  "message": {
    "template": "NOTIFICATION_TEMPLATE_ID",
    "to": {
      "email": "alice@acme.com"
    },
    "providers": {
      "mailersend": {
        "override": {
          "attachments": [
            {
              "filename": "billing.pdf",
              "contentType": "application/pdf",
              "data": "Q29uZ3JhdHVsYXRpb25zLCB5b3UgY2FuIGJhc2U2NCBkZWNvZGUh"
            }
          ]
        }
      }
    }
  }
}

Troubleshooting

A 422 error from MailerSend can have several causes:
ErrorCause
From email must be verifiedThe domain of the from email address must match the domain that the API token is from.
Must provide HTML/text or template IDThe API request is missing content; provide either an HTML/text body or a template ID.
File type not supportedThe attachment is not a supported file type.
Reply-to must be a valid emailThe reply_to parameter is not a valid email address.
Email quota reachedThe account’s quota has been reached. Ensure your account is approved for production sending.
The most common cause is an unverified sending domain. Make sure your domain is verified with MailerSend before using it with Courier.