mailersend
v3.4.0
Published
Node.js helper module for MailerSend API
Maintainers
Readme
MailerSend Node.js SDK
Welcome to MailerSend 👋
Send emails and SMS in minutes
Developers come for the high deliverability, and stay because our intuitive API and built-in integrations make life easier. 🤝
For more info, you can:
- Visit our Developers site 💻 for REST API reference
- Read our Knowledge base ❓ for guides on how to use MailerSend
- Contact our Support team 📨 if you require more assistance
V1 Documentation can be found here
Table of Contents
- Installation
- Usage
- Email
- Send an email
- Add CC, BCC recipients
- Send a template-based email
- Personalization
- Send email with attachment
- Send email with inline attachment
- Send email with references (threading)
- Send email with list-unsubscribe
- Send a scheduled email
- Send email with precedence bulk header
- Send an email with tracking
- Send email with custom headers
- Send an email with RCPT TO recipients
- Bulk email API
- Inbound Routing
- Activity
- Emails
- Analytics
- Domains
- Messages
- Scheduled Messages
- Tokens
- Recipients
- Webhooks
- Templates
- Email Verification
- SMS
- Phone Numbers
- SMS Messages
- SMS Activity
- SMS Recipients
- SMS Webhooks
- SMS Inbound
- Identity
- SMTP Users
- Users
- DMARC Monitoring
- Blocklist Monitoring
- Other endpoints
- Email
- Utils
- Support and Feedback
- License
Installation
Setup
npm install mailersendif you would like to use the env approach as shown in the examples, please run
npm install dotenv --saveUsage
Send an email
import 'dotenv/config';
import { MailerSend, EmailParams, Sender, Recipient } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
const sentFrom = new Sender("[email protected]", "Your name");
const recipients = [
new Recipient("[email protected]", "Your Client")
];
const emailParams = new EmailParams()
.setFrom(sentFrom)
.setTo(recipients)
.setReplyTo(sentFrom)
.setSubject("This is a Subject")
.setHtml("<strong>This is the HTML content</strong>")
.setText("This is the text content");
await mailerSend.email.send(emailParams);
Add CC, BCC recipients
import 'dotenv/config';
import { MailerSend, EmailParams, Sender, Recipient } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
const sentFrom = new Sender("[email protected]", "Your name");
const recipients = [
new Recipient("[email protected]", "Your Client")
];
const cc = [
new Recipient("[email protected]", "Your Client CC")
];
const bcc = [
new Recipient("[email protected]", "Your Client BCC")
];
const emailParams = new EmailParams()
.setFrom(sentFrom)
.setTo(recipients)
.setCc(cc)
.setBcc(bcc)
.setSubject("This is a Subject")
.setHtml("<strong>This is the HTML content</strong>")
.setText("This is the text content");
await mailerSend.email.send(emailParams);Send a template-based email
import 'dotenv/config';
import { MailerSend, EmailParams, Sender, Recipient } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
const sentFrom = new Sender("[email protected]", "Your name");
const recipients = [
new Recipient("[email protected]", "Your Client")
];
const emailParams = new EmailParams()
.setFrom(sentFrom)
.setTo(recipients)
.setReplyTo(sentFrom)
.setSubject("This is a Subject")
.setTemplateId('templateId');
await mailerSend.email.send(emailParams);
Send a template-based email in a specific language
The optional language field accepts a language code (for example de, fr, pt-BR). It only applies to template-based sends and is ignored for raw HTML/text emails. Supported values: de, en, es, fr, it, lt, nl, pl, pt-BR.
import 'dotenv/config';
import { MailerSend, EmailParams, Sender, Recipient } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
const sentFrom = new Sender("[email protected]", "Your name");
const recipients = [
new Recipient("[email protected]", "Your Client")
];
const emailParams = new EmailParams()
.setFrom(sentFrom)
.setTo(recipients)
.setReplyTo(sentFrom)
.setSubject("This is a Subject")
.setTemplateId('templateId')
.setLanguage("de");
await mailerSend.email.send(emailParams);
Personalization
import 'dotenv/config';
import { MailerSend, EmailParams, Sender, Recipient } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
const sentFrom = new Sender("[email protected]", "Your name");
const recipients = [
new Recipient("[email protected]", "Your Client")
];
const personalization = [
{
email: "[email protected]",
data: {
test: 'Test Value'
},
}
];
const emailParams = new EmailParams()
.setFrom(sentFrom)
.setTo(recipients)
.setReplyTo(sentFrom)
.setPersonalization(personalization)
.setSubject("Subject, {{ test }}")
.setHtml("This is the HTML content, {{ test }}")
.setText("This is the text content, {{ test }}");
await mailerSend.email.send(emailParams);
Send email with attachment
import 'dotenv/config';
import fs from "fs";
import { MailerSend, EmailParams, Sender, Recipient, Attachment } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
const sentFrom = new Sender("[email protected]", "Your name");
const recipients = [
new Recipient("[email protected]", "Your Client")
];
const attachments = [
new Attachment(
fs.readFileSync('/path/to/file.pdf', { encoding: 'base64' }),
'file.pdf',
'attachment'
)
]
const emailParams = new EmailParams()
.setFrom(sentFrom)
.setTo(recipients)
.setReplyTo(sentFrom)
.setAttachments(attachments)
.setSubject("This is a Subject")
.setHtml("<strong>This is the HTML content</strong>")
.setText("This is the text content");
await mailerSend.email.send(emailParams);
Send email with inline attachment
import 'dotenv/config';
import fs from "fs";
import { MailerSend, EmailParams, Sender, Recipient, Attachment } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
const sentFrom = new Sender("[email protected]", "Your name");
const recipients = [
new Recipient("[email protected]", "Your Client")
];
const attachments = [
new Attachment(
fs.readFileSync('/path/to/file.png', { encoding: 'base64' }),
'file.png',
'inline',
'0123456789'
)
]
const emailParams = new EmailParams()
.setFrom(sentFrom)
.setTo(recipients)
.setReplyTo(sentFrom)
.setAttachments(attachments)
.setSubject("This is a Subject")
.setHtml("<strong>This is the HTML content with an inline image attachment <img src=\"cid:0123456789\"/></strong>")
.setText("This is the text content");
await mailerSend.email.send(emailParams);
Send email with references (threading)
Note: The
referencesfield is available on paid plan accounts only.
import 'dotenv/config';
import { MailerSend, EmailParams, Sender, Recipient } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
const sentFrom = new Sender("[email protected]", "Your name");
const recipients = [
new Recipient("[email protected]", "Your Client")
];
const emailParams = new EmailParams()
.setFrom(sentFrom)
.setTo(recipients)
.setReplyTo(sentFrom)
.setSubject("Re: This is a Subject")
.setHtml("<strong>This is the HTML content</strong>")
.setText("This is the text content")
.setInReplyTo("<[email protected]>")
.setReferences([
"<[email protected]>",
"<[email protected]>",
]);
await mailerSend.email.send(emailParams);
Send email with list-unsubscribe
import 'dotenv/config';
import { MailerSend, EmailParams, Sender, Recipient } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
const sentFrom = new Sender("[email protected]", "Your name");
const recipients = [
new Recipient("[email protected]", "Your Client")
];
const emailParams = new EmailParams()
.setFrom(sentFrom)
.setTo(recipients)
.setReplyTo(sentFrom)
.setSubject("This is a Subject")
.setHtml("<strong>This is the HTML content</strong>")
.setText("This is the text content")
.setListUnsubscribe("https://www.yourdomain.com/unsubscribe");
await mailerSend.email.send(emailParams);
Send a scheduled message
import 'dotenv/config';
import { MailerSend, EmailParams, Sender, Recipient } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
const sentFrom = new Sender("[email protected]", "Your name");
const recipients = [
new Recipient("[email protected]", "Your Client")
];
const emailParams = new EmailParams()
.setFrom(sentFrom)
.setTo(recipients)
.setReplyTo(sentFrom)
.setSubject("This is a scheduled Subject")
.setHtml("<strong>This is a scheduled HTML content</strong>")
.setText("This is a scheduled text content")
// Accepts a Unix timestamp (integer) or an ISO 8601 date string
.setSendAt(Math.floor((new Date(Date.now() + 30 * 60 * 1000)).getTime() / 1000)); // Unix timestamp – send in 30 mins
// .setSendAt("2040-11-21T14:00:00+00:00"); // ISO 8601 alternative
await mailerSend.email.send(emailParams);
Send email with precedence bulk header
import 'dotenv/config';
import { MailerSend, EmailParams, Sender, Recipient } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
const sentFrom = new Sender("[email protected]", "Your name");
const recipients = [
new Recipient("[email protected]", "Your Client")
];
const emailParams = new EmailParams()
.setFrom(sentFrom)
.setTo(recipients)
.setReplyTo(sentFrom)
.setSubject("This is a Subject")
.setHtml("<strong>This is the HTML content</strong>")
.setText("This is the text content")
.setPrecedenceBulk(true);
await mailerSend.email.send(emailParams);
Send an email with tracking
import 'dotenv/config';
import { MailerSend, EmailParams, Sender, Recipient } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
const sentFrom = new Sender("[email protected]", "Your name");
const recipients = [
new Recipient("[email protected]", "Your Client")
];
const emailParams = new EmailParams()
.setFrom(sentFrom)
.setTo(recipients)
.setReplyTo(sentFrom)
.setSubject("This is a Subject")
.setHtml("<strong>This is the HTML content</strong>")
.setText("This is the text content")
.setSettings({
track_clicks: true,
track_opens: true,
track_content: true,
});
await mailerSend.email.send(emailParams);
Send email with custom headers
Note: Custom headers are available on Professional and Enterprise accounts only.
import 'dotenv/config';
import { MailerSend, EmailParams, Sender, Recipient } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
const sentFrom = new Sender("[email protected]", "Your name");
const recipients = [
new Recipient("[email protected]", "Your Client")
];
const headers = [
{ name: "X-Custom-Header", value: "custom-value" },
{ name: "X-Another-Header", value: "another-value" },
];
const emailParams = new EmailParams()
.setFrom(sentFrom)
.setTo(recipients)
.setReplyTo(sentFrom)
.setSubject("This is a Subject")
.setHtml("<strong>This is the HTML content</strong>")
.setText("This is the text content")
.setHeaders(headers);
await mailerSend.email.send(emailParams);
Send an email with RCPT TO recipients
rcptTois intended for SMTP source delivery and accepts a list of recipients. Whentois empty andrcptTois provided, the addresses are forwarded as BCC.
import 'dotenv/config';
import { MailerSend, EmailParams, Sender, Recipient } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
const sentFrom = new Sender("[email protected]", "Your name");
const rcptTo = [
new Recipient("[email protected]")
];
const emailParams = new EmailParams()
.setFrom(sentFrom)
.setSubject("This is a Subject")
.setHtml("<strong>This is the HTML content</strong>")
.setText("This is the text content")
.setRcptTo(rcptTo);
await mailerSend.email.send(emailParams);
Bulk email API
Send bulk email
import 'dotenv/config';
import { MailerSend, EmailParams, Sender, Recipient } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
const sentFrom = new Sender("[email protected]", "Your name");
const bulkEmails = [];
const emailParams = new EmailParams()
.setFrom(sentFrom)
.setTo([
new Recipient("[email protected]", "Your Client")
])
.setSubject("This is a Subject")
.setHtml("<strong>This is the HTML content</strong>")
.setText("This is the text content");
bulkEmails.push(emailParams);
const emailParams2 = new EmailParams()
.setFrom(sentFrom)
.setTo([
new Recipient("[email protected]", "Your Client 2")
])
.setSubject("This is a Subject 2")
.setHtml("<strong>This is the HTML content 2</strong>")
.setText("This is the text content 2");
bulkEmails.push(emailParams2);
await mailerSend.email.sendBulk(bulkEmails);
Get bulk request status
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.getBulkStatus('bulk_email_id') // bulk email Id e.g 63af1fdb790d97105a090001
.then((response) => {
console.log(response.body);
});
Inbound routing
Get a list of inbound routes
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.inbound.list()
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
With query parameters:
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.inbound.list({
domain_id: "domain_id",
page: 1,
limit: 25,
})
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Get a single inbound route
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.inbound.single("inbound_id")
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Add an inbound route
import 'dotenv/config';
import { MailerSend, Inbound, InboundFilterType } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
const inbound = new Inbound('inbound test', true, 'domain_id')
.setInboundDomain('inbound.yourdomain.com')
.setInboundPriority(50)
.setMatchFilter({
type: InboundFilterType.MATCH_ALL,
})
.setCatchFilter({
type: InboundFilterType.CATCH_RECIPIENT,
})
.setForwards([
{
type: "webhook",
value: "https://www.yourdomain.com/hook"
}
]);
mailerSend.email.inbound.create(inbound)
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Update an inbound route
import 'dotenv/config';
import { MailerSend, InboundUpdateParams, InboundFilterType } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
const inbound = new InboundUpdateParams('inbound test 2', false)
.setInboundDomain('inbound.yourdomain.com')
.setInboundPriority(25)
.setMatchFilter({
type: InboundFilterType.MATCH_ALL,
})
.setCatchFilter({
type: InboundFilterType.CATCH_ALL,
})
.setForwards([
{
type: "webhook",
value: "https://www.yourdomain.com/hook"
}
]);
mailerSend.email.inbound.update('inbound_id', inbound)
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Delete an inbound route
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.inbound.delete("inbound_id")
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Activity
Get activity list
import 'dotenv/config';
import { MailerSend, ActivityEventType } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
const queryParams = {
limit: 10, // Min: 10, Max: 100, Default: 25
page: 2,
date_from: 1443651141, // Unix timestamp
date_to: 1443651141, // Unix timestamp
event: [ActivityEventType.SENT, ActivityEventType.SOFT_BOUNCED, ActivityEventType.SUPPRESSED]
}
mailerSend.email.activity.domain("domain_id", queryParams)
.then((response) => console.log(response.body))
.catch((error) => console.log(error));
Activities of type suppressed also include a suppression_reason field, one of on_hold, hard_bounced, unsubscribed, spam_complained or blocklisted. Requires the Starter plan or above.
Get single activity
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.activity.single("activity_id")
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Emails
An email is the record of a message delivered to one recipient. Unlike activities, which return one row per event, these requests return one row per email with its current status and a summary of recipient interaction.
Get a list of emails
import 'dotenv/config';
import { MailerSend, EmailStatus, EmailInteraction } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
const queryParams = {
domain_id: "domain_id",
date_from: 1443651141, // Unix timestamp
date_to: 1443661141, // Unix timestamp
page: 1, // Min: 1, Max: 100, Default: 1
limit: 50, // Min: 10, Max: 1000, Default: 25
status: [EmailStatus.SENT, EmailStatus.DELIVERED],
interaction: [EmailInteraction.OPENED]
}
mailerSend.email.list(queryParams)
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
domain_id, date_from and date_to are required — every query is bound to a single domain and a single time window. Emails are returned newest first.
| Query parameter | Type | Required | Details |
|-------------------|---------------------------------|----------|----------------------------------------------------------------------------------------------------------------------------------|
| domain_id | string | yes | Must be a domain that belongs to your account. An unknown ID returns 404. |
| date_from | number \| string | yes | Unix timestamp (1443651141) or datetime (2015-10-01 00:00:00), assumed UTC. Must be lower than date_to and within your plan's data retention limit (1–30 days). |
| date_to | number \| string | yes | Unix timestamp or datetime, assumed UTC. Must be higher than date_from and must not be in the future. |
| page | number | no | Min: 1, Max: 100, Default: 1. See Pagination. |
| limit | number | no | Min: 10, Max: 1000, Default: 25. |
| status | EmailStatus[] | no | Any of queued, sent, rejected, delivered. Values are combined with OR. |
| interaction | EmailInteraction[] | no | Any of opened, clicked, unsubscribed, complained, no_interaction. Values are combined with OR. |
| recipient_email | string | no | Exact, case-insensitive match. An address with no emails returns 200 with an empty data array. |
| message_id | string | no | Alphanumeric. Exact match. |
| template_id | string | no | Exact match. |
| subject | string | no | Min: 3 characters. Partial, case-insensitive match. |
| tag | string | no | Exact match against a value in the email's tags array. |
status and interaction must be arrays. The two filters are combined with AND, so the example above returns emails that are sent or delivered and that were opened. EmailInteraction.NO_INTERACTION matches emails with none of opened, clicked, unsubscribed or complained recorded — it is a filter value only and is never returned in a response.
Requires a token with one of the activity_read or activity_full scopes. Requests are limited to 10 requests/minute, shared with Get activity list — requests to either endpoint count against the same per-account budget.
Pagination
This endpoint paginates with page and limit, exactly like Get activity list, so EmailsQueryParams extends the shared Pagination type. To walk the result set, request the next page until links.next is null:
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
const queryParams = {
domain_id: "domain_id",
date_from: 1443651141,
date_to: 1443661141,
limit: 100,
};
let page = 1;
let hasMore = true;
while (hasMore) {
const response = await mailerSend.email.list({ ...queryParams, page });
response.body.data.forEach((email) => console.log(email.id, email.status, email.subject));
hasMore = response.body.links.next !== null;
page++;
}
Every request has to repeat domain_id, date_from, date_to and any filters alongside page — dropping one of them returns 422. Keep limit the same across the whole walk, otherwise page boundaries shift underneath you.
Notes on the response envelope:
links.nextandlinks.prevare full URLs with all your query parameters preserved, ornullat the first and last page.links.lastis alwaysnull— the API does not report a last page for this endpoint.metacontainscurrent_page,current_page_url,from,path,per_pageandto. There is nototaland nolast_page, so checklinks.nextrather than trying to compute the page count up front.
A filter that matches nothing returns 200 with an empty data array, links.next: null and meta.from/meta.to set to null.
Types
EmailListResponse describes the response body, and EmailsQueryParams the query parameters:
import {
MailerSend,
EmailsQueryParams,
EmailListResponse,
EmailStatus,
EmailInteraction,
} from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY as string,
});
const queryParams: EmailsQueryParams = {
domain_id: "domain_id",
date_from: 1443651141,
date_to: 1443661141,
status: [EmailStatus.DELIVERED],
interaction: [EmailInteraction.CLICKED],
};
const response = await mailerSend.email.list(queryParams);
const emails: EmailListResponse = response.body;
Each item in data is an EmailListItem, with id, from, to, subject, text, html, template_id, domain_id, message_id, status, tags, interaction, suppression_reason, created_at, updated_at and headers.
textandhtmlare alwaysnullin list rows, whatever the email actually contained — the list query does not project the content columns. Use Get a single email to read the body. They are typedstring | nullrather thannullso one function can handle both a list row and a single email.tags,template_idandheadersarenullwhen unused.headersis an array of{ name, value }objects — the sameEmailHeadertype used when sending — not a flat object.interactionis an empty array when there was no interaction, and never containsno_interaction.suppression_reasonis only set whenstatusisrejected.- List rows carry no
recipientand noactivity— use Get a single email for those.
Get a single email
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.single("email_id")
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
| URL parameter | Type | Required | Details |
|---------------|----------|----------|------------------------------------------------------------|
| email_id | string | yes | The id of an email, as returned by Get a list of emails. |
Requires a token with one of the email_full, activity_read or activity_full scopes. An email that does not exist or belongs to another account returns 404.
The response carries the full email: id, from, to, subject, text, html, template_id, domain_id, message_id, status, tags, interaction, suppression_reason, created_at, updated_at, recipient, headers and activity. Unlike a list row, text and html hold the actual content here, and recipient and activity are present.
Alongside the email's content, data.activity holds the activity events recorded for it:
| Response key | Type | Details |
|--------------------------------------|------------|-------------------------------------------------------------------------------------------------------------|
| data.activity[].id | string | ID of the event. Pass it to Get single activity for the full event. |
| data.activity[].type | string | The event type. |
| data.activity[].created_at | string | |
| data.activity[].suppression_reason | string | Only present on suppressed events. One of on_hold, hard_bounced, unsubscribed, spam_complained, blocklisted. |
- Events are returned newest first and are capped at 200 events per email. There is no pagination on this array — use Get activity list if you need the complete event history for a domain.
- The
junkevent type is reported assoft_bounced. deferredandsuppressedevents are only included if your plan has those features enabled. They are available on the Starter plan and above.activityis returned even when content tracking is disabled for the domain. In that casehtmlandtextarenull, but the events are still present.template_idisnullwhen the email was not sent from a template.
EmailResponse describes the response body, Email the email itself, and EmailActivityEvent an entry in data.activity:
import { MailerSend, EmailResponse } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY as string,
});
const response = await mailerSend.email.single("email_id");
const email: EmailResponse = response.body;
email.data.activity.forEach((event) => console.log(event.type, event.created_at));
Analytics
Get activity data by date
import 'dotenv/config';
import { ActivityEventType, AnalyticsDateQueryParams, AnalyticsGroupByType, MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
const queryParams: AnalyticsDateQueryParams = {
date_from: 1443651141,
date_to: 2443651141,
event: [ActivityEventType.CLICKED, ActivityEventType.OPENED],
// group_by: AnalyticsGroupByType.DAYS, // optional: days, weeks, months, years
};
mailerSend.email.analytics.byDate(queryParams).then(response => {
console.log(response.body);
}).catch(error => {
console.log(error.body);
});
Opens by country
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.analytics.byCountry({
date_from: 1443651141,
date_to: 2443651141,
}).then(response => {
console.log(response.body);
}).catch(error => {
console.log(error.body);
});
Opens by user-agent
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.analytics.byUserAgent({
date_from: 1443651141,
date_to: 2443651141,
}).then(response => {
console.log(response.body);
}).catch(error => {
console.log(error.body);
});
Opens by reading environment
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.analytics.byReadingEnvironment({
date_from: 1443651141,
date_to: 2443651141,
}).then(response => {
console.log(response.body);
}).catch(error => {
console.log(error.body);
});
Domains
Get a list of domains
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.domain.list()
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.domain.list({ page: 1, limit: 10, verified: true })
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Get domain
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.domain.single("domain_id")
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Add a domain
import 'dotenv/config';
import { MailerSend, Domain } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
const domain = new Domain(
"example.com",
"rp_subdomain",
"ct_subdomain",
"ir_subdomain",
)
mailerSend.email.domain.create(domain)
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Delete domain
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.domain.delete("domain_id")
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Get a list of recipients per domain
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.domain.recipients("domain_id", {
page: 1,
limit: 10
})
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Update domain settings
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.domain.updateSettings("domain_id", {
send_paused: true,
track_clicks: true,
track_opens: true,
track_unsubscribe: true,
track_unsubscribe_html: "<strong> Unsubscribe now </strong>",
track_unsubscribe_plain: "Unsubscribe now",
track_unsubscribe_html_enabled: true,
track_unsubscribe_plain_enabled: true,
track_content: true,
custom_tracking_enabled: true,
custom_tracking_subdomain: "subdomain",
precedence_bulk: true,
ignore_duplicated_recipients: true,
})
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Verify a domain
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.domain.verify("domain_id")
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Get DNS records
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.domain.dns("domain_id")
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Messages
Get a list of messages
import 'dotenv/config';
import { MailerSend} from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.message.list()
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Get info on a message
import 'dotenv/config';
import { MailerSend} from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.message.single("message_id")
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Scheduled Messages
Get scheduled email list
import 'dotenv/config';
import { MailerSend} from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.schedule.list({
domain_id: "domain_id",
status: "scheduled", // "scheduled" | "sent" | "error"
limit: 10,
page: 1,
})
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Get scheduled email
import 'dotenv/config';
import { MailerSend} from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.schedule.single("message_id")
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Delete scheduled email
import 'dotenv/config';
import { MailerSend} from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.schedule.delete("message_id")
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Tokens
List tokens
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.token.list({ page: 1, limit: 25 })
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Get token
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.token.single("token_id")
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Create a token
import 'dotenv/config';
import { MailerSend, Token, TokenScopeType } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
const token = new Token("Token name", [
TokenScopeType.EMAIL_FULL,
TokenScopeType.DOMAINS_READ,
TokenScopeType.DOMAINS_FULL,
TokenScopeType.ACTIVITY_READ,
TokenScopeType.ACTIVITY_FULL,
TokenScopeType.ANALYTICS_READ,
TokenScopeType.ANALYTICS_FULL,
TokenScopeType.TOKENS_FULL,
], "domain_id");
mailerSend.token.create(token)
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Update token name
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.token.update("token_id", { name: "New token name" })
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Update token status
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.token.updateSettings("token_id", {
status: "pause",
})
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Delete token
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.token.delete("token_id")
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Recipients
Get a list of recipients
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.recipient.list({
domain_id: "domain_id",
limit: 10,
})
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Get single recipient
import 'dotenv/config';
import { MailerSend} from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.recipient.single("recipient_id")
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Delete recipient
import 'dotenv/config';
import { MailerSend} from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.recipient.delete("recipient_id")
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Add recipients to a suppression list
Blocklist
import 'dotenv/config';
import { BlockListType, MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.recipient.blockRecipients({
domain_id: 'domain_id',
recipients: [
"[email protected]"
]
}, BlockListType.BLOCK_LIST)
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Hard Bounces
import 'dotenv/config';
import { BlockListType, MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.recipient.blockRecipients({
domain_id: 'domain_id',
recipients: [
"[email protected]"
]
}, BlockListType.HARD_BOUNCES_LIST)
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Spam Complaints
import 'dotenv/config';
import { BlockListType, MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.recipient.blockRecipients({
domain_id: 'domain_id',
recipients: [
"[email protected]"
]
}, BlockListType.SPAM_COMPLAINTS_LIST)
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Unsubscribe
import 'dotenv/config';
import { BlockListType, MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.recipient.blockRecipients({
domain_id: 'domain_id',
recipients: [
"[email protected]"
]
}, BlockListType.UNSUBSCRIBES_LIST)
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Delete recipients from a suppression list
Blocklist
import 'dotenv/config';
import { BlockListType, MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.recipient.delBlockListRecipients(
["recipient_id", "recipient_id"],
BlockListType.BLOCK_LIST
)
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Hard Bounce
import 'dotenv/config';
import { BlockListType, MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.recipient.delBlockListRecipients(
["recipient_id", "recipient_id"],
BlockListType.HARD_BOUNCES_LIST
)
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Spam Complaint
import 'dotenv/config';
import { BlockListType, MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.recipient.delBlockListRecipients(
["recipient_id", "recipient_id"],
BlockListType.SPAM_COMPLAINTS_LIST
)
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Unsubscribe
import 'dotenv/config';
import { BlockListType, MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.recipient.delBlockListRecipients(
["recipient_id", "recipient_id"],
BlockListType.UNSUBSCRIBES_LIST
)
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Get recipients from a suppression list
Blocklist
import 'dotenv/config';
import { BlockListType, MailerSend} from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.recipient.blockList(
{ domain_id: "domain_id", },
BlockListType.BLOCK_LIST
)
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Hard Bounce
import 'dotenv/config';
import { BlockListType, MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.recipient.blockList(
{ domain_id: "domain_id", },
BlockListType.HARD_BOUNCES_LIST
)
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Spam Complaint
import 'dotenv/config';
import { BlockListType, MailerSend} from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.recipient.blockList(
{ domain_id: "domain_id", },
BlockListType.SPAM_COMPLAINTS_LIST
)
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Unsubscribe
import 'dotenv/config';
import { BlockListType, MailerSend} from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.recipient.blockList(
{ domain_id: "domain_id", },
BlockListType.UNSUBSCRIBES_LIST
)
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Delete all recipients from a suppression list
import 'dotenv/config';
import { BlockListType, MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.recipient.delAllBlockListRecipients(BlockListType.BLOCK_LIST)
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Get recipients from the on-hold list
import 'dotenv/config';
import { BlockListType, MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.recipient.blockList(
{ page: 1, limit: 25 },
BlockListType.ON_HOLD_LIST
)
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Delete recipients from the on-hold list
import 'dotenv/config';
import { BlockListType, MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.recipient.delBlockListRecipients(
["recipient_id", "recipient_id"],
BlockListType.ON_HOLD_LIST
)
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Webhooks
Get a list of webhooks
import 'dotenv/config';
import { MailerSend} from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.webhook.list("domain_id")
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
import 'dotenv/config';
import { MailerSend} from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.webhook.list("domain_id", { limit: 25, page: 2 })
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Get webhook
import 'dotenv/config';
import { MailerSend} from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.webhook.single("webhook_id")
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Create webhook
import 'dotenv/config';
import { EmailWebhook, EmailWebhookEventType, MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
const emailWebhook = new EmailWebhook()
.setName("Webhook Name")
.setUrl("https://example.com")
.setDomainId("domain_id")
.setEnabled(true)
.setEvents([EmailWebhookEventType.SENT, EmailWebhookEventType.OPENED]);
mailerSend.email.webhook.create(emailWebhook)
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
import 'dotenv/config';
import { EmailWebhook, EmailWebhookEventType, MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
const emailWebhook = new EmailWebhook()
.setName("Webhook Name")
.setUrl("https://example.com")
.setDomainId("domain_id")
.setEnabled(true)
.setVersion(2)
.setEditable(true)
.setEvents([EmailWebhookEventType.SENT, EmailWebhookEventType.OPENED]);
mailerSend.email.webhook.create(emailWebhook)
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
import 'dotenv/config';
import { EmailWebhook, EmailWebhookEventType, MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
const emailWebhook = new EmailWebhook()
.setName("Webhook Name")
.setUrl("https://example.com")
.setDomainId("domain_id")
.setEnabled(false)
.setEvents([EmailWebhookEventType.SENT, EmailWebhookEventType.OPENED]);
mailerSend.email.webhook.create(emailWebhook)
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Update webhook
import 'dotenv/config';
import { EmailWebhookEventType, MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.webhook.update("webhook_id", {
name: "Webhook Name 2",
url: "https://example.com/updated-hook",
enabled: false,
events: [EmailWebhookEventType.SENT, EmailWebhookEventType.OPENED],
version: 2,
})
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Delete webhook
import 'dotenv/config';
import { MailerSend} from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.webhook.delete("webhook_id")
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Templates
Get a list of templates
import 'dotenv/config';
import { MailerSend} from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.template.list({
domain_id: "domain_id"
})
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
import 'dotenv/config';
import { MailerSend} from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.template.list({
domain_id: "domain_id",
page: 1,
limit: 25,
})
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Get a single template
import 'dotenv/config';
import { MailerSend} from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.template.single("template_id")
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Create a template
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.template.create({
name: "My Template",
html: "<p>Hello, {{name}}!</p>",
text: "Hello, {{name}}!",
domain_id: "domain_id",
categories: ["welcome"],
tags: ["welcome"],
auto_generate: false,
})
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Update a template
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.template.update("template_id", {
name: "Updated Template Name",
html: "<p>Hello, {{name}}! Updated.</p>",
text: "Hello, {{name}}! Updated.",
auto_generate: true,
})
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Delete a template
import 'dotenv/config';
import { MailerSend} from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.template.delete("template_id")
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Email Verification
Get all email verification lists
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.emailVerification.list({ page: 1, limit: 25 })
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Get an email verification list
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.emailVerification.single("email_verification_id", {
detailed: true,
page: 1,
limit: 25,
})
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Create an email verification list
import 'dotenv/config';
import { MailerSend, EmailVerification } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
const emailVerification = new EmailVerification("My List", [
"[email protected]",
"[email protected]",
]);
// Optional: link to an existing list and trigger verification automatically
// emailVerification.setListId("existing_list_id");
// emailVerification.setVerify(true);
mailerSend.emailVerification.create(emailVerification)
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Verify an email list
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.emailVerification.verifyList("email_verification_id")
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Get email verification list results
import 'dotenv/config';
import { MailerSend, EmailVerificationResultType } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.emailVerification.getListResult("email_verification_id", {
page: 1,
limit: 25,
results: [EmailVerificationResultType.VALID, EmailVerificationResultType.CATCH_ALL],
})
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Verify a single email
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.emailVerification.verifyEmail("[email protected]")
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Verify a single email asynchronously
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.emailVerification.verifyEmailAsync("[email protected]")
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Get async email verification status
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.emailVerification.getVerifyEmailAsyncStatus("verification_job_id")
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Send a WhatsApp message
import 'dotenv/config';
import { MailerSend, WhatsAppParams } from "mailersend";
const mailersend = new MailerSend({
apiKey: process.env.API_KEY,
});
const whatsappParams = new WhatsAppParams()
.setFrom("12345678901")
.setTo(["19191234567"])
.setTemplateId("template_id_123");
await mailersend.whatsapp.send(whatsappParams);
WhatsApp personalization
Values are positional: the first value of each array replaces {{1}} in that section of the template, the second replaces {{2}}, and so on. setButtons() takes the URL parameters appended to the template's URL buttons, not full URLs.
import 'dotenv/config';
import { MailerSend, WhatsAppParams, WhatsAppPersonalization } from "mailersend";
const mailersend = new MailerSend({
apiKey: process.env.API_KEY,
});
const personalization = [
new WhatsAppPersonalization("19191234567")
.setHeader(["John"])
.setBody(["order #1234", "tomorrow"])
.setButtons(["track/1234"]),
new WhatsAppPersonalization("19199876543")
.setHeader(["Jane"])
.setBody(["order #5678", "Friday"])
.setButtons(["track/5678"]),
];
const whatsappParams = new WhatsAppParams()
.setFrom("12345678901")
.setTo(["19191234567", "19199876543"])
.setTemplateId("template_id_123")
.setPersonalization(personalization);
await mailersend.whatsapp.send(whatsappParams);
SMS
Send SMS
import 'dotenv/config';
import { MailerSend, SMSParams } from "mailersend";
const mailersend = new MailerSend({
apiKey: process.env.API_KEY,
});
const recipients = [
"+18332647501"
];
const smsParams = new SMSParams()
.setFrom("+18332647501")
.setTo(recipients)
.setText("This is the text content");
await mailersend.sms.send(smsParams);
SMS personalization
import 'dotenv/config';
import { MailerSend, SMSParams, SMSPersonalization } from "mailersend";
const mailersend = new MailerSend({
apiKey: process.env.API_KEY,
});
const recipients = [
"+18332647501",
"+18332647502"
];
const personalization = [
new SMSPersonalization("+18332647501", {
"name": "Dummy"
}),
new SMSPersonalization("+18332647502", {
"name": "Not Dummy"
}),
];
const smsParams = new SMSParams()
.setFrom("+18332647501")
.setTo(recipients)
.setPersonalization(personalization)
.setText("Hey {{name}} welcome to our organization");
await mailersend.sms.send(smsParams);
Phone Numbers
Get phone number list
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.sms.number.list({
paused: false,
limit: 10,
page: 1
})
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Get phone number
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.sms.number.single("sms_number_id")
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
Update phone number
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.sms.number.update("sms_number_id", true)
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
