Videos
Check out our tutorial video series.
How to send emails in code and tests. Use MailSlurp email APIs in Javascript, Java, PHP, CSharp and more. Works with SMTP clients or REST SDKs.
You can send emails from any MailSlurp inbox that you have created.
Free MailSlurp accounts cannot send emails to some common email domains such as and
(paid accounts aren't affected). This is to reduce spam.
To send emails to all addresses please use a paid account or contact support. For more information see the sending limits page.
The simplest email you can send only requires a recipient and an inbox.
This will send an empty email from the inboxes email address to the recipient. Most emails however are more complicated than this. Let us see the options next.
For all sending options see the SendEmailOptions reference docs. For forwarding and auto-forwarding rules see the forwarding guide.
Emails have a and
header. Emails use the inbox email address by default for
and
. You can set these as options:
Setting custom headers is not recommended if you wish to maintain a good spam rating. You should instead set an inbox's
property and that will be included in the headers automatically along with the inbox's email address.
You can provide ,
, and
recipient lists. Each must be in array format.
Example:
Each recipient must be a valid email address and can either be specified directly or with a name:
If your email address uses special characters encode it first using Punycode local encoding on part before the sign.
=
You can specify subject as follows:
The body of an email is a string. If the body includes HTML set to ensure the correct
header is used with the email.
You can specify character encoding with the charset option, eg: . See i18n guide for more information.
You can also send HTML by setting . All emails are UTF-8 by default and [support i18n].
Here is a full example with multiline HTML and UTF8 characters.
When sending HTML you should use tables and inlined CSS for better rendering in most clients.
You can submit a list of attachment IDs when sending emails to attach files. You must upload the files before sending using the attachment upload endpoints.
MailSlurp expects files as base 64 encoded strings. You can do this by reading a file as bytes and then converting those to base64. Here is an example using NodeJS:
When you send emails from a free account Mailslurp monitors email bounces. A bounce is when an email is rejected by an email provider. To avoid bounce warnings upgrade to a paid account and use email verification or webhooks to manage bounces.
To ensure your account always delivers emails regardless of bounce status or payment failures use queue-backed email sending or the option when sending to remove any bounced recipients from your recipient list.
MailSlurp provides email verification services to reduce bounce rates and increase delivery.
You can verify email addresses before sending via the validation methods:
You can also verify email during sending so that all recipients are automatically validated. Configure the validation options when sending to either filter out and remove bad recipients from the recipient list or throw an error to prevent sending.
You can delay email sending by using a job schedule. Use message queues to send with asynchronous message queues that can recover if delivery fails.
MailSlurp supports sending emails using SQS-backed message queues. This means that outbound emails are placed on a queue and can be retried and recovered if sending is blocked for your account or a recipient is not accepting messages. Check your plan for feature support.
Schedule email sending at later dates like so:
See the scheduling guide for more.
MailSlurp supports sending emails with predefined templates.
Templates can be created in code or designed in the dashboard. Templates support HTML, variables, and handlebars templating syntax. Unlike other services MailSlurp will warn you if you try to send a template with missing variables.
MailSlurp supports email templates for sending automated emails with variable replacements.
If you want to use variables in your templates simple wrap each variable in double curly braces:
MailSlurp will recognize the and
variables which can then be supplied as a map of
in
methods. They will also be displayed in the dashboard:
When you send an email with a template you can pass a map of template variables and values.
MailSlurp will validate emails and return an error if passed variable names do not match template variables.
MailSlurp also supports contact and contact groups. You can create these in the dashboard.
To send an email to a contact use the property:
To send emails to each contact in a group use the property.
Check out our tutorial video series.
Email and SMS guides for automation and testing.
View github project code for multiple languages.
Latest posts from the MailSlurp team.
Test, build, and automate messaging with a free MailSlurp account.