Repository: mailersend/mailersend-nodejs Branch: main Commit: 0772cef40398 Files: 280 Total size: 315.5 KB Directory structure: gitextract_ii8zs4um/ ├── .editorconfig ├── .github/ │ ├── CODEOWNERS │ └── workflows/ │ ├── publish.yaml │ └── test.yaml ├── .gitignore ├── LICENSE ├── README.md ├── examples/ │ ├── v1/ │ │ ├── activity/ │ │ │ ├── byCountry.js │ │ │ ├── byDate.js │ │ │ ├── byReadingEnvironment.js │ │ │ ├── byUserAgent.js │ │ │ └── list.js │ │ ├── domains/ │ │ │ ├── add.js │ │ │ ├── delete.js │ │ │ ├── dns.js │ │ │ ├── list.js │ │ │ ├── recipients.js │ │ │ ├── settings.js │ │ │ ├── single.js │ │ │ └── verify.js │ │ ├── email/ │ │ │ ├── advancedPersonalization.js │ │ │ ├── ccBccRecipients.js │ │ │ ├── getBulkEmailRequestStatus.js │ │ │ ├── sendAnEmail.js │ │ │ ├── sendBulkEmail.js │ │ │ ├── sendScheduleEmail.js │ │ │ ├── simplePersonalization.js │ │ │ ├── templatedEmail.js │ │ │ └── withAttachment.js │ │ ├── email-verification/ │ │ │ ├── create.js │ │ │ ├── list.js │ │ │ ├── results.js │ │ │ ├── single.js │ │ │ └── verify.js │ │ ├── inbounds/ │ │ │ ├── create.js │ │ │ ├── delete.js │ │ │ ├── list.js │ │ │ ├── single.js │ │ │ └── update.js │ │ ├── messages/ │ │ │ ├── list.js │ │ │ └── single.js │ │ ├── recipients/ │ │ │ ├── addRecipientsToBlocklist.js │ │ │ ├── addRecipientsToHardBounceList.js │ │ │ ├── addRecipientsToSpamComplaintList.js │ │ │ ├── addRecipientsToUnsubscribeList.js │ │ │ ├── delete.js │ │ │ ├── deleteRecipientsFromBlocklist.js │ │ │ ├── deleteRecipientsFromHardBounceList.js │ │ │ ├── deleteRecipientsFromSpamComplaintList.js │ │ │ ├── deleteRecipientsFromUnsubscribeList.js │ │ │ ├── getRecipientsFromBlocklist.js │ │ │ ├── getRecipientsFromHardBounceList.js │ │ │ ├── getRecipientsFromSpamComplaintList.js │ │ │ ├── getRecipientsFromUnsubscribeList.js │ │ │ ├── list.js │ │ │ └── single.js │ │ ├── scheduled/ │ │ │ ├── delete.js │ │ │ ├── list.js │ │ │ └── single.js │ │ ├── sms/ │ │ │ ├── activities/ │ │ │ │ ├── list.js │ │ │ │ └── single.js │ │ │ ├── inbounds/ │ │ │ │ ├── create.js │ │ │ │ ├── delete.js │ │ │ │ ├── list.js │ │ │ │ ├── single.js │ │ │ │ └── update.js │ │ │ ├── messages/ │ │ │ │ ├── list.js │ │ │ │ └── single.js │ │ │ ├── numbers/ │ │ │ │ ├── delete.js │ │ │ │ ├── list.js │ │ │ │ ├── single.js │ │ │ │ └── update.js │ │ │ ├── recipients/ │ │ │ │ ├── list.js │ │ │ │ ├── single.js │ │ │ │ └── update.js │ │ │ ├── sendAnSms.js │ │ │ ├── smsPersonalization.js │ │ │ └── webhooks/ │ │ │ ├── create.js │ │ │ ├── delete.js │ │ │ ├── list.js │ │ │ ├── single.js │ │ │ └── update.js │ │ ├── templates/ │ │ │ ├── delete.js │ │ │ ├── list.js │ │ │ └── single.js │ │ ├── tokens/ │ │ │ ├── createToken.js │ │ │ ├── deleteToken.js │ │ │ └── updateToken.js │ │ └── webhooks/ │ │ ├── create.js │ │ ├── delete.js │ │ ├── list.js │ │ ├── single.js │ │ └── update.js │ └── v2/ │ ├── email/ │ │ ├── activity/ │ │ │ └── list.js │ │ ├── advancedPersonalization.js │ │ ├── analytics/ │ │ │ ├── byCountry.js │ │ │ ├── byDate.js │ │ │ ├── byReadingEnvironment.js │ │ │ └── byUserAgent.js │ │ ├── ccBccRecipients.js │ │ ├── domains/ │ │ │ ├── add.js │ │ │ ├── delete.js │ │ │ ├── dns.js │ │ │ ├── list.js │ │ │ ├── recipients.js │ │ │ ├── settings.js │ │ │ ├── single.js │ │ │ └── verify.js │ │ ├── getBulkEmailRequestStatus.js │ │ ├── identities/ │ │ │ ├── create.js │ │ │ ├── delete.js │ │ │ ├── deleteByEmail.js │ │ │ ├── list.js │ │ │ ├── single.js │ │ │ ├── singleByEmail.js │ │ │ ├── update.js │ │ │ └── updateByEmail.js │ │ ├── inbounds/ │ │ │ ├── create.js │ │ │ ├── delete.js │ │ │ ├── list.js │ │ │ ├── single.js │ │ │ └── update.js │ │ ├── messages/ │ │ │ ├── list.js │ │ │ └── single.js │ │ ├── recipients/ │ │ │ ├── addRecipientsToBlocklist.js │ │ │ ├── addRecipientsToHardBounceList.js │ │ │ ├── addRecipientsToSpamComplaintList.js │ │ │ ├── addRecipientsToUnsubscribeList.js │ │ │ ├── delete.js │ │ │ ├── deleteAllBlocklistRecipients.js │ │ │ ├── deleteRecipientsFromBlocklist.js │ │ │ ├── deleteRecipientsFromHardBounceList.js │ │ │ ├── deleteRecipientsFromSpamComplaintList.js │ │ │ ├── deleteRecipientsFromUnsubscribeList.js │ │ │ ├── getRecipientsFromBlocklist.js │ │ │ ├── getRecipientsFromHardBounceList.js │ │ │ ├── getRecipientsFromSpamComplaintList.js │ │ │ ├── getRecipientsFromUnsubscribeList.js │ │ │ ├── list.js │ │ │ └── single.js │ │ ├── scheduled/ │ │ │ ├── delete.js │ │ │ ├── list.js │ │ │ └── single.js │ │ ├── sendAnEmail.js │ │ ├── sendBulkEmail.js │ │ ├── sendScheduleEmail.js │ │ ├── simplePersonalization.js │ │ ├── templatedEmail.js │ │ ├── templates/ │ │ │ ├── delete.js │ │ │ ├── list.js │ │ │ └── single.js │ │ ├── webhooks/ │ │ │ ├── create.js │ │ │ ├── delete.js │ │ │ ├── list.js │ │ │ ├── single.js │ │ │ └── update.js │ │ └── withAttachment.js │ ├── email-verification/ │ │ ├── create.js │ │ ├── list.js │ │ ├── results.js │ │ ├── single.js │ │ ├── verifyEmail.js │ │ └── verifyList.js │ ├── others/ │ │ └── getApiQuota.js │ ├── sms/ │ │ ├── activities/ │ │ │ ├── list.js │ │ │ └── single.js │ │ ├── inbounds/ │ │ │ ├── create.js │ │ │ ├── delete.js │ │ │ ├── list.js │ │ │ ├── single.js │ │ │ └── update.js │ │ ├── messages/ │ │ │ ├── list.js │ │ │ └── single.js │ │ ├── numbers/ │ │ │ ├── delete.js │ │ │ ├── list.js │ │ │ ├── single.js │ │ │ └── update.js │ │ ├── recipients/ │ │ │ ├── list.js │ │ │ ├── single.js │ │ │ └── update.js │ │ ├── sendAnSms.js │ │ ├── smsPersonalization.js │ │ └── webhooks/ │ │ ├── create.js │ │ ├── delete.js │ │ ├── list.js │ │ ├── single.js │ │ └── update.js │ └── tokens/ │ ├── createToken.js │ ├── deleteToken.js │ └── updateToken.js ├── jestconfig.json ├── package.json ├── renovate.json ├── src/ │ ├── __tests__/ │ │ ├── modules/ │ │ │ ├── Activity.test.ts │ │ │ ├── Analytics.test.ts │ │ │ ├── BlocklistMonitor.test.ts │ │ │ ├── Dmarc.test.ts │ │ │ ├── Domain.test.ts │ │ │ ├── Email.test.ts │ │ │ ├── EmailVerification.test.ts │ │ │ ├── Identity.test.ts │ │ │ ├── Inbound.test.ts │ │ │ ├── MailerSend.test.ts │ │ │ ├── Message.test.ts │ │ │ ├── Others.test.ts │ │ │ ├── Recipient.test.ts │ │ │ ├── SMS.test.ts │ │ │ ├── Schedule.test.ts │ │ │ ├── SmsActivity.test.ts │ │ │ ├── SmsInbound.test.ts │ │ │ ├── SmsMessage.test.ts │ │ │ ├── SmsNumber.test.ts │ │ │ ├── SmsRecipient.test.ts │ │ │ ├── SmsWebhook.test.ts │ │ │ ├── SmtpUser.test.ts │ │ │ ├── Template.test.ts │ │ │ ├── Token.test.ts │ │ │ ├── User.test.ts │ │ │ └── Webhook.test.ts │ │ └── services/ │ │ ├── mailersend.utils.test.ts │ │ └── request.test.ts │ ├── index.ts │ ├── models/ │ │ ├── BlocklistMonitor.ts │ │ ├── EmailVerification.ts │ │ ├── Pagination.ts │ │ ├── Token.ts │ │ ├── User.ts │ │ ├── email/ │ │ │ ├── Activity.ts │ │ │ ├── Analytics.ts │ │ │ ├── Attachment.ts │ │ │ ├── Dmarc.ts │ │ │ ├── Domain.ts │ │ │ ├── EmailParams.ts │ │ │ ├── EmailWebhook.ts │ │ │ ├── Identity.ts │ │ │ ├── Inbound.ts │ │ │ ├── Message.ts │ │ │ ├── Recipient.ts │ │ │ ├── Schedule.ts │ │ │ ├── Sender.ts │ │ │ ├── SmtpUser.ts │ │ │ └── Template.ts │ │ ├── index.ts │ │ └── sms/ │ │ ├── Activity.ts │ │ ├── Inbound.ts │ │ ├── Message.ts │ │ ├── Number.ts │ │ ├── Recipient.ts │ │ ├── SMSParams.ts │ │ ├── SMSPersonalization.ts │ │ └── Webhook.ts │ ├── modules/ │ │ ├── BlocklistMonitor.module.ts │ │ ├── Dmarc.module.ts │ │ ├── Email.module.ts │ │ ├── EmailVerification.module.ts │ │ ├── MailerSend.module.ts │ │ ├── Others.module.ts │ │ ├── SMS.module.ts │ │ ├── Token.module.ts │ │ ├── User.module.ts │ │ ├── email/ │ │ │ ├── Activity.module.ts │ │ │ ├── Analytics.module.ts │ │ │ ├── Domain.module.ts │ │ │ ├── Identity.module.ts │ │ │ ├── Inbound.module.ts │ │ │ ├── Message.module.ts │ │ │ ├── Recipient.module.ts │ │ │ ├── Schedule.module.ts │ │ │ ├── SmtpUser.module.ts │ │ │ ├── Template.module.ts │ │ │ └── Webhook.module.ts │ │ └── sms/ │ │ ├── Activity.module.ts │ │ ├── Inbound.module.ts │ │ ├── Message.module.ts │ │ ├── Number.module.ts │ │ ├── Recipient.module.ts │ │ └── Webhook.module.ts │ └── services/ │ ├── mailersend.utils.ts │ └── request.service.ts └── tsconfig.json ================================================ FILE CONTENTS ================================================ ================================================ FILE: .editorconfig ================================================ root = true [*] charset = utf-8 end_of_line = lf insert_final_newline = true indent_style = space indent_size = 2 trim_trailing_whitespace = true ================================================ FILE: .github/CODEOWNERS ================================================ * @mailersend/nodejs-sdk-maintainers ================================================ FILE: .github/workflows/publish.yaml ================================================ name: NPM Publish on: release: types: [created] jobs: build: runs-on: ubuntu-24.04 permissions: id-token: write steps: - uses: actions/checkout@v6 - uses: actions/setup-node@v6 with: node-version: 24 registry-url: "https://registry.npmjs.org" - run: npm install - run: npm publish ================================================ FILE: .github/workflows/test.yaml ================================================ name: Tests on: push: branches: [main] pull_request: jobs: test: runs-on: ubuntu-24.04 strategy: matrix: node-version: [20, 22, 24] name: Node ${{ matrix.node-version }} Tests steps: - name: Checkout uses: actions/checkout@v4 - name: Setup Node uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - name: Cache node_modules id: node-cache uses: actions/cache@v4 with: path: node_modules key: ${{ runner.os }}-node${{ matrix.node-version }}-${{ hashFiles('package-lock.json') }} restore-keys: ${{ runner.os }}-node${{ matrix.node-version }}- - name: Install dependencies if: steps.node-cache.outputs.cache-hit != 'true' run: npm install - name: Run test suite run: npm test ================================================ FILE: .gitignore ================================================ node_modules .env .DS_Store .idea /lib ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2020 MailerSend Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ MailerSend Node.js SDK [![MIT licensed](https://img.shields.io/npm/l/mailersend)](./LICENSE.md) ![NPM Version](https://img.shields.io/npm/v/mailersend) ![Top language](https://img.shields.io/github/languages/top/IARKI/mailer-send-ts)
## 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 💻](https://developers.mailersend.com/) for REST API reference - Read our [Knowledge base ❓](https://www.mailersend.com/help) for guides on how to use MailerSend - Contact our [Support team 📨](https://www.mailersend.com/contact-us) if you require more assistance #### V1 Documentation can be found [here](https://github.com/mailersend/mailersend-nodejs/tree/v1#readme)
# Table of Contents - [Installation](#installation) - [Setup](#setup) - [Usage](#usage) - [Email](#email) - [Send an email](#send-an-email) - [Add CC, BCC recipients](#add-cc-bcc-recipients) - [Send a template-based email](#send-a-template-based-email) - [Personalization](#advanced-personalization) - [Send email with attachment](#send-email-with-attachment) - [Send email with inline attachment](#send-email-with-inline-attachment) - [Send email with references (threading)](#send-email-with-references-threading) - [Send email with list-unsubscribe](#send-email-with-list-unsubscribe) - [Send a scheduled email](#send-a-scheduled-email) - [Send email with precedence bulk header](#send-email-with-precedence-bulk-header) - [Send an email with tracking](#send-an-email-with-tracking) - [Send email with custom headers](#send-email-with-custom-headers) - [Send an email with RCPT TO recipients](#send-an-email-with-rcpt-to-recipients) - [Bulk email API](#bulk-email-api) - [Send bulk emails](#send-bulk-emails) - [Get bulk request status](#get-bulk-request-status) - [Inbound Routing](#inbound) - [Get inbound list](#get-inbound-list) - [Get inbound](#get-inbound) - [Create inbound](#create-inbound) - [Update inbound](#update-inbound) - [Delete inbound](#delete-inbound) - [Activity](#activity) - [Get activity list](#get-activity-list) - [Get single activity](#get-single-activity) - [Analytics](#analytics) - [Get activity data by date](#get-activity-data-by-date) - [Opens by country](#opens-by-country) - [Opens by user-agent](#opens-by-user-agent) - [Opens by reading environment](#opens-by-reading-environment) - [Domains](#domains) - [Get a list of domains](#get-a-list-of-domains) - [Get domain](#get-domain) - [Add a domain](#add-a-domain) - [Delete domain](#delete-domain) - [Get a list of recipients per domain](#get-a-list-of-recipients-per-domain) - [Update domain settings](#update-domain-settings) - [Verify a domain](#verify-a-domain) - [Get DNS records](#get-dns-records) - [Messages](#messages) - [Get a list of messages](#get-a-list-of-messages) - [Get info on a message](#get-info-on-a-message) - [Scheduled Messages](#scheduled-messages) - [Get scheduled email list](#get-scheduled-email-list) - [Get scheduled email](#get-scheduled-email) - [Delete scheduled email](#delete-scheduled-email) - [Tokens](#tokens) - [List tokens](#list-tokens) - [Get token](#get-token) - [Create a token](#create-a-token) - [Update token name](#update-token-name) - [Update token status](#update-token-status) - [Delete token](#delete-token) - [Recipients](#recipients) - [Get a list of recipients](#get-a-list-of-recipients) - [Get single recipient](#get-single-recipient) - [Delete recipient](#delete-recipient) - [Add recipients to a suppression list](#add-recipients-to-a-suppression-list) - [Delete recipients from a suppression list](#delete-recipients-from-a-suppression-list) - [Get recipients from a suppression list](#get-recipients-from-a-suppression-list) - [Delete all recipients from a suppression list](#delete-all-recipients-from-a-suppression-list) - [Get recipients from the on-hold list](#get-recipients-from-the-on-hold-list) - [Delete recipients from the on-hold list](#delete-recipients-from-the-on-hold-list) - [Webhooks](#webhooks) - [Get a list of webhooks](#get-a-list-of-webhooks) - [Get webhook](#get-webhook) - [Create webhook](#create-webhook) - [Update webhook](#update-webhook) - [Delete webhook](#delete-webhook) - [Templates](#templates) - [Get a list of templates](#get-a-list-of-templates) - [Get a single template](#get-a-single-template) - [Create a template](#create-a-template) - [Update a template](#update-a-template) - [Delete a template](#delete-a-template) - [Email Verification](#email-verification) - [Get all email verification lists](#get-all-email-verification-lists) - [Get an email verification list](#get-an-email-verification-list) - [Create an email verification list](#create-an-email-verification-list) - [Verify an email list](#verify-an-email-list) - [Get email verification list results](#get-email-verification-list-results) - [Verify a single email](#verify-a-single-email) - [Verify a single email asynchronously](#verify-a-single-email-asynchronously) - [Get async email verification status](#get-async-email-verification-status) - [SMS](#sms) - [Send SMS](#send-sms) - [SMS personalization](#sms-personalization) - [Phone Numbers](#phone-numbers) - [Get phone number list](#get-phone-number-list) - [Get phone number](#get-phone-number) - [Update phone number](#update-phone-number) - [Delete phone number](#delete-phone-number) - [SMS Messages](#messages-1) - [Get messages list](#get-messages-list) - [Get a message](#get-a-message) - [SMS Activity](#activity-1) - [Get activity list](#get-activity-list-1) - [SMS Recipients](#recipients-1) - [Get recipient list](#get-recipient-list) - [Get recipient](#get-recipient) - [Update recipient](#update-recipient) - [SMS Webhooks](#webhooks-1) - [Get webhook list for a number](#get-webhook-list-for-a-number) - [Get webhook](#get-webhook-1) - [Create webhook](#create-webhook-1) - [Update webhook](#update-webhook-1) - [Delete webhook](#delete-webhook-1) - [SMS Inbound](#inbound-1) - [Get inbound list](#get-inbound-list-1) - [Get inbound](#get-inbound-1) - [Add inbound](#add-inbound) - [Update inbound](#update-inbound-1) - [Delete inbound](#delete-inbound-1) - [Identity](#identity) - [Get identity list](#get-identity-list) - [Get identity](#get-identity) - [Get identity by email](#get-identity-by-email-address) - [Create identity](#create-identity) - [Update identity](#update-identity) - [Update identity by email](#update-identity-by-email-address) - [Delete identity](#delete-identity) - [Delete identity by email](#delete-identity-by-email-address) - [Resend identity verification](#resend-identity-verification) - [SMTP Users](#smtp-users) - [List SMTP users](#list-smtp-users) - [Get SMTP user](#get-smtp-user) - [Create SMTP user](#create-smtp-user) - [Update SMTP user](#update-smtp-user) - [Delete SMTP user](#delete-smtp-user) - [Users](#users) - [Get user list](#get-user-list) - [Get single user](#get-single-user) - [Invite a user](#invite-a-user) - [Update user](#update-user) - [Delete user](#delete-user) - [Get invite list](#get-invite-list) - [Get single invite](#get-single-invite) - [Resend invite](#resend-invite) - [Cancel invite](#cancel-invite) - [DMARC Monitoring](#dmarc-monitoring) - [List monitors](#list-monitors) - [Create monitor](#create-monitor) - [Update monitor](#update-monitor) - [Delete monitor](#delete-monitor) - [Get aggregated reports](#get-aggregated-reports) - [Get IP-specific reports](#get-ip-specific-reports) - [Get report sources](#get-report-sources) - [Mark IP as favorite](#mark-ip-as-favorite) - [Remove IP from favorites](#remove-ip-from-favorites) - [Blocklist Monitoring](#blocklist-monitoring) - [List blocklist monitors](#list-blocklist-monitors) - [Get single blocklist monitor](#get-single-blocklist-monitor) - [Create blocklist monitor](#create-blocklist-monitor) - [Update blocklist monitor](#update-blocklist-monitor) - [Delete blocklist monitor](#delete-blocklist-monitor) - [Other endpoints](#other-endpoints) - [Get API quota](#get-api-quota) - [Utils](#utils) - [Verify a webhook signature](#verify-a-webhook-signature) - [Support and Feedback](#support-and-feedback) - [License](#license) ## Installation ### Setup ```bash npm install mailersend ``` if you would like to use the env approach as shown in the examples, please run ```bash npm install dotenv --save ``` ## Usage ## Email ### Send an email ```js import 'dotenv/config'; import { MailerSend, EmailParams, Sender, Recipient } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const sentFrom = new Sender("you@yourdomain.com", "Your name"); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const emailParams = new EmailParams() .setFrom(sentFrom) .setTo(recipients) .setReplyTo(sentFrom) .setSubject("This is a Subject") .setHtml("This is the HTML content") .setText("This is the text content"); await mailerSend.email.send(emailParams); ``` ### Add CC, BCC recipients ```js import 'dotenv/config'; import { MailerSend, EmailParams, Sender, Recipient } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const sentFrom = new Sender("bbbb@yourdomain.com", "Your name"); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const cc = [ new Recipient("your_cc@client.com", "Your Client CC") ]; const bcc = [ new Recipient("your_bcc@client.com", "Your Client BCC") ]; const emailParams = new EmailParams() .setFrom(sentFrom) .setTo(recipients) .setCc(cc) .setBcc(bcc) .setSubject("This is a Subject") .setHtml("This is the HTML content") .setText("This is the text content"); await mailerSend.email.send(emailParams); ``` ### Send a template-based email ```js import 'dotenv/config'; import { MailerSend, EmailParams, Sender, Recipient } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const sentFrom = new Sender("you@yourdomain.com", "Your name"); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const emailParams = new EmailParams() .setFrom(sentFrom) .setTo(recipients) .setReplyTo(sentFrom) .setSubject("This is a Subject") .setTemplateId('templateId'); await mailerSend.email.send(emailParams); ``` ### Personalization ```js import 'dotenv/config'; import { MailerSend, EmailParams, Sender, Recipient } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const sentFrom = new Sender("you@yourdomain.com", "Your name"); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const personalization = [ { email: "your@client.com", 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 ```js 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("you@yourdomain.com", "Your name"); const recipients = [ new Recipient("your@client.com", "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("This is the HTML content") .setText("This is the text content"); await mailerSend.email.send(emailParams); ``` ### Send email with inline attachment ```js 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("you@yourdomain.com", "Your name"); const recipients = [ new Recipient("your@client.com", "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("This is the HTML content with an inline image attachment ") .setText("This is the text content"); await mailerSend.email.send(emailParams); ``` ### Send email with references (threading) > **Note:** The `references` field is available on paid plan accounts only. ```js import 'dotenv/config'; import { MailerSend, EmailParams, Sender, Recipient } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const sentFrom = new Sender("you@yourdomain.com", "Your name"); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const emailParams = new EmailParams() .setFrom(sentFrom) .setTo(recipients) .setReplyTo(sentFrom) .setSubject("Re: This is a Subject") .setHtml("This is the HTML content") .setText("This is the text content") .setInReplyTo("") .setReferences([ "", "", ]); await mailerSend.email.send(emailParams); ``` ### Send email with list-unsubscribe ```js import 'dotenv/config'; import { MailerSend, EmailParams, Sender, Recipient } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const sentFrom = new Sender("you@yourdomain.com", "Your name"); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const emailParams = new EmailParams() .setFrom(sentFrom) .setTo(recipients) .setReplyTo(sentFrom) .setSubject("This is a Subject") .setHtml("This is the HTML content") .setText("This is the text content") .setListUnsubscribe("https://www.yourdomain.com/unsubscribe"); await mailerSend.email.send(emailParams); ``` ### Send a scheduled message ```js import 'dotenv/config'; import { MailerSend, EmailParams, Sender, Recipient } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const sentFrom = new Sender("you@yourdomain.com", "Your name"); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const emailParams = new EmailParams() .setFrom(sentFrom) .setTo(recipients) .setReplyTo(sentFrom) .setSubject("This is a scheduled Subject") .setHtml("This is a scheduled HTML content") .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 ```js import 'dotenv/config'; import { MailerSend, EmailParams, Sender, Recipient } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const sentFrom = new Sender("you@yourdomain.com", "Your name"); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const emailParams = new EmailParams() .setFrom(sentFrom) .setTo(recipients) .setReplyTo(sentFrom) .setSubject("This is a Subject") .setHtml("This is the HTML content") .setText("This is the text content") .setPrecedenceBulk(true); await mailerSend.email.send(emailParams); ``` ### Send an email with tracking ```js import 'dotenv/config'; import { MailerSend, EmailParams, Sender, Recipient } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const sentFrom = new Sender("you@yourdomain.com", "Your name"); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const emailParams = new EmailParams() .setFrom(sentFrom) .setTo(recipients) .setReplyTo(sentFrom) .setSubject("This is a Subject") .setHtml("This is the HTML content") .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. ```js import 'dotenv/config'; import { MailerSend, EmailParams, Sender, Recipient } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const sentFrom = new Sender("you@yourdomain.com", "Your name"); const recipients = [ new Recipient("your@client.com", "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("This is the HTML content") .setText("This is the text content") .setHeaders(headers); await mailerSend.email.send(emailParams); ``` ### Send an email with RCPT TO recipients > `rcptTo` is intended for SMTP source delivery and accepts a list of recipients. > When `to` is empty and `rcptTo` is provided, the addresses are forwarded as BCC. ```js import 'dotenv/config'; import { MailerSend, EmailParams, Sender, Recipient } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const sentFrom = new Sender("you@yourdomain.com", "Your name"); const rcptTo = [ new Recipient("rcpt@client.com") ]; const emailParams = new EmailParams() .setFrom(sentFrom) .setSubject("This is a Subject") .setHtml("This is the HTML content") .setText("This is the text content") .setRcptTo(rcptTo); await mailerSend.email.send(emailParams); ``` ## Bulk email API ### Send bulk email ```js import 'dotenv/config'; import { MailerSend, EmailParams, Sender, Recipient } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const sentFrom = new Sender("your@yourdomain.com", "Your name"); const bulkEmails = []; const emailParams = new EmailParams() .setFrom(sentFrom) .setTo([ new Recipient("your@client.com", "Your Client") ]) .setSubject("This is a Subject") .setHtml("This is the HTML content") .setText("This is the text content"); bulkEmails.push(emailParams); const emailParams2 = new EmailParams() .setFrom(sentFrom) .setTo([ new Recipient("your_2@client.com", "Your Client 2") ]) .setSubject("This is a Subject 2") .setHtml("This is the HTML content 2") .setText("This is the text content 2"); bulkEmails.push(emailParams2); await mailerSend.email.sendBulk(bulkEmails); ``` ### Get bulk request status ```js 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 ```js 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: ```js 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 ```js 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 ```js 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 ```js 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 ```js 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 ```js 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] } mailerSend.email.activity.domain("domain_id", queryParams) .then((response) => console.log(response.body)) .catch((error) => console.log(error)); ``` ### Get single activity ```js 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)); ``` ## Analytics ### Get activity data by date ```js 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 ```js 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 ```js 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 ```js 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 ```js 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)); ``` ```js 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 ```js 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 ```js 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 ```js 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 ```js 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 ```js 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: " Unsubscribe now ", 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 ```js 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 ```js 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 ```js 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 ```js 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 ```js 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 ```js 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 ```js 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 ```js 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 ```js 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 ```js 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 ```js 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 ```js 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 ```js 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 ```js 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 ```js 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 ```js 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 ```js 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: [ "test@example.com" ] }, BlockListType.BLOCK_LIST) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` #### Hard Bounces ```js 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: [ "test@example.com" ] }, BlockListType.HARD_BOUNCES_LIST) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` #### Spam Complaints ```js 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: [ "test@example.com" ] }, BlockListType.SPAM_COMPLAINTS_LIST) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` #### Unsubscribe ```js 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: [ "test@example.com" ] }, BlockListType.UNSUBSCRIBES_LIST) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Delete recipients from a suppression list #### Blocklist ```js 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 ```js 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 ```js 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 ```js 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 ```js 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 ```js 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 ```js 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 ```js 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 ```js 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 ```js 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 ```js 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 ```js 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)); ``` ```js 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 ```js 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 ```js 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)); ``` ```js 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)); ``` ```js 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 ```js 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 ```js 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 ```js 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)); ``` ```js 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 ```js 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 ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.template.create({ name: "My Template", html: "

Hello, {{name}}!

", 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 ```js 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: "

Hello, {{name}}! Updated.

", text: "Hello, {{name}}! Updated.", auto_generate: true, }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Delete a template ```js 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 ```js 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 ```js 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 ```js import 'dotenv/config'; import { MailerSend, EmailVerification } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const emailVerification = new EmailVerification("My List", [ "test1@example.com", "test2@example.com", ]); // 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 ```js 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 ```js 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 ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.emailVerification.verifyEmail("test@example.com") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Verify a single email asynchronously ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.emailVerification.verifyEmailAsync("test@example.com") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get async email verification status ```js 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)); ``` ## SMS ### Send SMS ```js 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 ```js 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 ```js 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 ```js 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 ```js 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)); ``` ### Delete phone number ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.number.delete("sms_number_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ## Messages ### Get messages list ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.message.list({ limit: 10, page: 1 }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get a message ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.message.single("sms_message_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ## Activity ### Get activity list ```js import 'dotenv/config'; import { MailerSend, SmsActivityStatusType } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.activity.list({ sms_number_id: "number_id", status: [SmsActivityStatusType.SENT, SmsActivityStatusType.DELIVERED], limit: 10, page: 1 }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ## Recipients ### Get recipient list ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.recipient.list({ sms_number_id: "sms_number_id", status: "active", limit: 10, page: 1, }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get recipient ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.recipient.single("sms_recipient_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Update recipient ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.recipient.update("sms_recipient_id", "active") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ## Webhooks ### Get webhook list for a number ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.webhook.list("sms_number_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get webhook ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.webhook.single("sms_webhook_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Create webhook ```js import 'dotenv/config'; import { MailerSend, SmsWebhook, SmsWebhookEventType } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const smsWebhook = new SmsWebhook() .setName("Sms Webhook") .setUrl("https:://yourapp.com/hook") .setSmsNumberId("sms_number_id") .setEnabled(true) .setEvents([SmsWebhookEventType.SENT, SmsWebhookEventType.DELIVERED]) mailerSend.sms.webhook.create(smsWebhook) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Update webhook ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.webhook.update("sms_webhook_id", { name: "Webhook", url: "https:://yourapp.com/hook", enabled: ["sms.sent", "sms.delivered", "sms.failed"], enabled: true }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Delete webhook ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.webhook.delete("sms_webhook_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Verify webhook signature See [Utils — Verify a webhook signature](#verify-a-webhook-signature). ## Inbound ### Get inbound list ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.inbound.list({ enabled: 1, sms_number_id: "sms_number_id", limit: 10, page: 1, }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get inbound ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.inbound.single("sms_inbound_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Add inbound ```js import 'dotenv/config'; import { MailerSend, SmsInbound } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const smsInbound = new SmsInbound() .setSmsNumberId("sms_number_id") .setEnabled(true) .setName("Inbound Name") .setForwardUrl("yourapp.com/hook") .setFilter({ comparer: "equal", value: "START" }); mailerSend.sms.inbound.create(smsInbound) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Update inbound ```js import 'dotenv/config'; import { MailerSend, SmsInbound } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const smsInbound = new SmsInbound() .setSmsNumberId("sms_number_id") .setEnabled(true) .setName("Inbound Name Update") .setForwardUrl("yourapp.com/hook") .setFilter({ comparer: "equal", value: "START" }); mailerSend.sms.inbound.update("sms_inbound_id", {...smsInbound}) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Delete inbound ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.inbound.delete("sms_inbound_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ## Identity ### Get identity list ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.identity.list() .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get identity ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.identity.single("identity_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get identity by email address ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.identity.singleByEmail('email_address') .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Create identity ```js import 'dotenv/config'; import { MailerSend, Inbound, InboundFilterType } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const identity = new Identity() .setDomainId('domain_id') .setEmail('identity@yourdomain.com') .setName('Name') .setReplyToEmail('reply_identity@yourdomain.com') .setReplyToName('Reply Name') .setAddNote(false); mailerSend.email.identity.create(identity) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Update identity ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const data = { name: 'name', reply_to_name: 'Reply Name', reply_to_email: 'reply@yourdomain.com', }; mailerSend.email.identity.update('identity_id', data) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Update identity by email address ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const data = { name: 'name', reply_to_name: 'Reply Name', reply_to_email: 'reply@yourdomain.com', }; mailerSend.email.identity.updateByEmail('email_address', data) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Delete identity ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.identity.delete("identity_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Delete identity by email address ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.identity.deleteByEmail('email_address') .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Resend identity verification ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.identity.resend("identity_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ## SMTP Users ### List SMTP users ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.smtpUser.list("domain_id", { page: 1, limit: 25 }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get SMTP user ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.smtpUser.single("domain_id", "smtp_user_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Create SMTP user ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.smtpUser.create("domain_id", { name: "My SMTP User", enabled: true, }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Update SMTP user ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.smtpUser.update("domain_id", "smtp_user_id", { name: "Updated SMTP User", enabled: false, }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Delete SMTP user ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.smtpUser.delete("domain_id", "smtp_user_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ## Users ### Get user list ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.user.list({ page: 1, limit: 25 }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get single user ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.user.single("user_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Invite a user ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.user.create({ email: "user@example.com", role: "manager", // For role "custom", permissions is required: // permissions: ["read-activity", "read-analytics"], // templates: ["template_id"], // domains: ["domain_id"], }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Update user ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.user.update("user_id", { role: "designer", }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Delete user ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.user.delete("user_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get invite list ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.user.listInvites({ page: 1, limit: 25 }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get single invite ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.user.singleInvite("invite_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Resend invite ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.user.resendInvite("invite_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Cancel invite ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.user.deleteInvite("invite_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ## DMARC Monitoring ### List monitors ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.dmarc.list({ page: 1, limit: 25 }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Create monitor ```js import 'dotenv/config'; import { MailerSend, Dmarc } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const dmarc = new Dmarc("domain_id"); mailerSend.dmarc.create(dmarc) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Update monitor ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.dmarc.update("monitor_id", { wanted_dmarc_record: "v=DMARC1; p=reject;" }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Delete monitor ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.dmarc.delete("monitor_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get aggregated reports ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.dmarc.report("monitor_id", { page: 1, limit: 25 }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get IP-specific reports ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.dmarc.reportByIp("monitor_id", "1.2.3.4", { page: 1, limit: 25 }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get report sources ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.dmarc.reportSources("monitor_id", { date_from: 1700000000, date_to: 1700100000, status: "accepted", // optional: "accepted" | "rejected" | "quarantined" }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Mark IP as favorite ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.dmarc.addFavorite("monitor_id", "1.2.3.4") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Remove IP from favorites ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.dmarc.removeFavorite("monitor_id", "1.2.3.4") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ## Blocklist Monitoring ### List blocklist monitors ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.blocklistMonitor.list({ page: 1, limit: 25 }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get single blocklist monitor ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.blocklistMonitor.single("monitor_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Create blocklist monitor ```js import 'dotenv/config'; import { MailerSend, BlocklistMonitor } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const monitor = new BlocklistMonitor("example.com") .setName("My Domain Monitor") .setNotify(true) .setNotifyEmail("alerts@example.com"); mailerSend.blocklistMonitor.create(monitor) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Update blocklist monitor ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.blocklistMonitor.update("monitor_id", { name: "Updated Monitor Name", notify: true, notify_email: "alerts@example.com", }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Delete blocklist monitor ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.blocklistMonitor.delete("monitor_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ## Other endpoints ### Get API quota ```js import 'dotenv/config'; import { MailerSend} from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.others.getApiQuota() .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ## Utils ### Verify a webhook signature Use `MailerSendUtils.verifyWebHook()` to verify the HMAC signature on incoming webhook requests. This works for both email and SMS webhooks. ```js import { MailerSendUtils } from "mailersend"; // rawBody must be the raw Buffer from the request (do not parse it as JSON first) const isValid = MailerSendUtils.verifyWebHook( rawBody, request.headers['x-mailersend-signature'], process.env.WEBHOOK_SIGNING_SECRET ); ``` # Support and Feedback In case you find any bugs, submit an issue directly here in GitHub. You are welcome to create SDK for any other programming language. If you have any troubles using our API or SDK free to contact our support by email [info@mailersend.com](mailto:info@mailersend.com) The official documentation is at [https://developers.mailersend.com](https://developers.mailersend.com) # License [The MIT License (MIT)](LICENSE) ================================================ FILE: examples/v1/activity/byCountry.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.activityByCountry({ date_from: 1443651141, date_to: 2443651141 }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/activity/byDate.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.activityByDate({ date_from: 1443651141, date_to: 2443651141, event: ["sent"] }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/activity/byReadingEnvironment.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.activityByReadingEnvironment({ date_from: 1443651141, date_to: 2443651141 }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/activity/byUserAgent.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.activityByUserAgent({ date_from: 1443651141, date_to: 2443651141 }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/activity/list.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.activityList({ domain_id: "xxx", }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/domains/add.js ================================================ "use strict"; require("dotenv").config(); const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.addDomain({ name: "example.com", return_path_subdomain: "rp_subdomain", custom_tracking_subdomain: "ct_subdomain", inbound_routing_subdomain: "ir_subdomain", }) .then((response) => response.json()) .then((data) => { console.log(data); }); ================================================ FILE: examples/v1/domains/delete.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.deleteDomain({ domain_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/domains/dns.js ================================================ "use strict"; require("dotenv").config(); const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getDNS({ domain_id: "xxx", }) .then((response) => { response.json(); }) .then((data) => { console.log(data); }); ================================================ FILE: examples/v1/domains/list.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.domainList({ }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/domains/recipients.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.domainRecipients({ domain_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/domains/settings.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.domainSettings({ domain_id: 'xxx', send_paused: false }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/domains/single.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.domain({ domain_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/domains/verify.js ================================================ "use strict"; require("dotenv").config(); const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.verifyDomain({ domain_id: "xxx", }) .then((response) => { response.json(); }) .then((data) => { console.log(data); }); ================================================ FILE: examples/v1/email/advancedPersonalization.js ================================================ "use strict"; require('dotenv').config() const Recipient = require("../../src/Recipient"); const EmailParams = require("../../src/EmailParams"); const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const personalization = [ { email: "your@client.com", data: { test: 'Test Value' }, } ]; const emailParams = new EmailParams() .setFrom("your@domain.com") .setFromName("Your Name") .setRecipients(recipients) .setPersonalization(personalization) .setSubject("Subject, {{ test }}") .setHtml("This is the HTML content, {{ test }}") .setText("This is the text content, {{ test }}"); mailersend.send(emailParams); ================================================ FILE: examples/v1/email/ccBccRecipients.js ================================================ "use strict"; require('dotenv').config() const Recipient = require("../../src/Recipient"); const EmailParams = require("../../src/EmailParams"); const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const cc = [ new Recipient("your_cc@client.com", "Your CC Client") ]; const bcc = [ new Recipient("your_bcc@client.com", "Your BCC Client") ]; const emailParams = new EmailParams() .setFrom("your@domain.com") .setFromName("Your Name") .setRecipients(recipients) .setCc(cc) .setBcc(bcc) .setSubject("Subject") .setHtml("This is the HTML content") .setText("This is the text content"); mailersend.send(emailParams); ================================================ FILE: examples/v1/email/getBulkEmailRequestStatus.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getBulkEmailRequestStatus({ bulk_email_id: 'xxx' }) .then((response) => response.json()) .then((data) => { console.log(data); }); ================================================ FILE: examples/v1/email/sendAnEmail.js ================================================ "use strict"; require('dotenv').config() const Recipient = require("../../src/Recipient"); const EmailParams = require("../../src/EmailParams"); const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const emailParams = new EmailParams() .setFrom("your@domain.com") .setFromName("Your Name") .setRecipients(recipients) .setReplyTo("reply@domain.com") .setReplyToName("Reply to name") .setSubject("Subject") .setHtml("This is the HTML content") .setText("This is the text content"); mailersend.send(emailParams); ================================================ FILE: examples/v1/email/sendBulkEmail.js ================================================ "use strict"; require('dotenv').config() const Recipient = require("../../src/Recipient"); const EmailParams = require("../../src/EmailParams"); const MailerSend = require("../../src/MailerSend"); const BulkEmails = require("../../src/BulkEmails"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); const bulkEmails = new BulkEmails(); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const emailParams = new EmailParams() .setFrom("your@domain.com") .setFromName("Your Name") .setRecipients(recipients) .setSubject("Subject") .setHtml("This is the HTML content") .setText("This is the text content"); bulkEmails.addEmail(emailParams) bulkEmails.addEmails([ emailParams, emailParams ]) mailersend.sendBulk(bulkEmails) .then((response) => response.json()) .then((data) => { console.log(data); }); ================================================ FILE: examples/v1/email/sendScheduleEmail.js ================================================ "use strict"; require('dotenv').config() const Recipient = require("../../src/Recipient"); const EmailParams = require("../../src/EmailParams"); const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const emailParams = new EmailParams() .setFrom("your@domain.com") .setFromName("Your Name") .setRecipients(recipients) .setReplyTo("reply@domain.com") .setReplyToName("Reply to name") .setSubject("Subject") .setSendAt(2443651141) //set sendAt is a timestamp - min: now, max: now + 72hours .setHtml("This is the HTML content") .setText("This is the text content"); mailersend.send(emailParams); ================================================ FILE: examples/v1/email/simplePersonalization.js ================================================ "use strict"; require('dotenv').config() // const Recipient = require("../../src/Recipient"); const EmailParams = require("../../src/EmailParams"); const MailerSend = require("../../src/MailerSend"); const { default: Recipient } = require('../../src/Recipient'); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const variables = [ { email: "your@client.com", substitutions: [ { var: 'test', value: 'Test Value' } ], } ]; const emailParams = new EmailParams() .setFrom("your@domain.com") .setFromName("Your Name") .setRecipients(recipients) .setVariables(variables) .setSubject("Subject, {$test}") .setHtml("This is the HTML content, {$test}") .setText("This is the text content, {$test}"); mailersend.send(emailParams); ================================================ FILE: examples/v1/email/templatedEmail.js ================================================ "use strict"; require('dotenv').config() const Recipient = require("../../src/Recipient"); const EmailParams = require("../../src/EmailParams"); const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const emailParams = new EmailParams() .setFrom("your@domain.com") .setFromName("Your Name") .setRecipients(recipients) .setTemplateId('templateId') .setSubject("Subject") mailersend.send(emailParams); ================================================ FILE: examples/v1/email/withAttachment.js ================================================ "use strict"; require('dotenv').config() const fs = require('fs'); const Recipient = require("../../src/Recipient"); const Attachment = require("../../src/Attachment"); const EmailParams = require("../../src/EmailParams"); const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const attachments = [ new Attachment(fs.readFileSync('/path/to/file.pdf', {encoding: 'base64'}), 'file.pdf', 'attachment') ] const emailParams = new EmailParams() .setFrom("your@domain.com") .setFromName("Your Name") .setRecipients(recipients) .setAttachments(attachments) .setSubject("Subject") .setHtml("This is the HTML content") .setText("This is the text content"); mailersend.send(emailParams); ================================================ FILE: examples/v1/email-verification/create.js ================================================ "use strict"; require("dotenv").config(); const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.createEmailVerificationList({ name: "List example", emails: [ "info@mailersend.com", "test@mailersend.com" ] }) .then((response) => response.json()) .then((data) => { console.log(data); }); ================================================ FILE: examples/v1/email-verification/list.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.emailVerificationLists({ }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/email-verification/results.js ================================================ "use strict"; require("dotenv").config(); const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.emailVerificationResults({ email_verification_id: "xxx", }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/email-verification/single.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.emailVerificationList({ email_verification_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/email-verification/verify.js ================================================ "use strict"; require("dotenv").config(); const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.verifyEmailVerificationList({ email_verification_id: "xxx", }) .then((response) => response.json()) .then((data) => { console.log(data); }); ================================================ FILE: examples/v1/inbounds/create.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.createInbound({ domain_id: "xxx", name: "Test name", domain_enabled: true, inbound_domain: "test.yourdomain.com", inbound_address: "test@inbound.yourdomain.com", inbound_subdomain: "inbound", inbound_priority: 100, match_filter: { type: "match_all" }, catch_filter: { type: "catch_recipient", filters: [ { comparer: "equal", value: "test" } ] }, forwards: [ { type: "webhook", value: "https://www.yourdomain.com/hook" } ] }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/inbounds/delete.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.deleteInbound({ inbound_id: 'xxx' }); ================================================ FILE: examples/v1/inbounds/list.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.inboundList() .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/inbounds/single.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.inbound({ inbound_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/inbounds/update.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.updateInbound({ inbound_id: "xxx", domain_id: "xxx", name: "Test name", domain_enabled: true, inbound_domain: "test.yourdomain.com", inbound_address: "test@inbound.yourdomain.com", inbound_subdomain: "inbound", inbound_priority: 100, match_filter: { type: "match_all" }, catch_filter: { type: "catch_recipient", filters: [ { comparer: "equal", value: "test" } ] }, forwards: [ { type: "webhook", value: "https://www.yourdomain.com/hook" } ] }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/messages/list.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.messagesList() .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/messages/single.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.message({ message_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/recipients/addRecipientsToBlocklist.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.addRecipientsToBlocklist({ domain_id: 'xxx', recipients: [ "test@example.com" ] }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/recipients/addRecipientsToHardBounceList.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.addRecipientsToHardBounceList({ domain_id: 'xxx', recipients: [ "test@example.com" ] }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/recipients/addRecipientsToSpamComplaintList.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.addRecipientsToSpamComplaintList({ domain_id: 'xxx', recipients: [ "test@example.com" ] }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/recipients/addRecipientsToUnsubscribeList.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.addRecipientsToUnsubscribeList({ domain_id: 'xxx', recipients: [ "test@example.com" ] }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/recipients/delete.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.deleteRecipient({ recipient_id: 'xxx' }); ================================================ FILE: examples/v1/recipients/deleteRecipientsFromBlocklist.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.deleteRecipientsFromBlocklist({ ids: [ "xxxxxxxxxxx", "yyyyyyyyyyy" ] }); ================================================ FILE: examples/v1/recipients/deleteRecipientsFromHardBounceList.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.deleteRecipientsFromHardBounceList({ ids: [ "xxxxxxxxxxx", "yyyyyyyyyyy" ] }); ================================================ FILE: examples/v1/recipients/deleteRecipientsFromSpamComplaintList.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.deleteRecipientsFromSpamComplaintList({ ids: [ "xxxxxxxxxxx", "yyyyyyyyyyy" ] }); ================================================ FILE: examples/v1/recipients/deleteRecipientsFromUnsubscribeList.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.deleteRecipientsFromUnsubscribeList({ ids: [ "xxxxxxxxxxx", "yyyyyyyyyyy" ] }); ================================================ FILE: examples/v1/recipients/getRecipientsFromBlocklist.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getRecipientsFromBlocklist({ domain_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/recipients/getRecipientsFromHardBounceList.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getRecipientsFromHardBounceList({ domain_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/recipients/getRecipientsFromSpamComplaintList.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getRecipientsFromSpamComplaintList({ domain_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/recipients/getRecipientsFromUnsubscribeList.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getRecipientsFromUnsubscribeList({ domain_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/recipients/list.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.recipientsList() .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/recipients/single.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.recipient({ recipient_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/scheduled/delete.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.deleteSchedule({ message_id: 'xxx' }); ================================================ FILE: examples/v1/scheduled/list.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.scheduleList() .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/scheduled/single.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.schedule({ message_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/activities/list.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getSmsActivities() .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/activities/single.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getSmsActivity({ sms_message_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/inbounds/create.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.createSmsInbound({ sms_number_id: "xxx", name: "Inbound", forward_url: "https:://yourapp.com/hook", filter: { comparer: "equal", value: "START" }, enabled: true }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/inbounds/delete.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.deleteSmsInbound({ sms_inbound_id: 'xxx' }); ================================================ FILE: examples/v1/sms/inbounds/list.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getSmsInbounds() .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/inbounds/single.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getSmsInbound({ sms_inbound_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/inbounds/update.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.updateSmsInbound({ sms_inbound_id: "xxx", name: "Inbound", forward_url: "https:://yourapp.com/hook", filter: { comparer: "equal", value: "START" }, enabled: true }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/messages/list.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getSmsMessages() .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/messages/single.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getSmsMessage({ sms_message_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/numbers/delete.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.deleteSmsNumber({ sms_number_id: 'xxx' }); ================================================ FILE: examples/v1/sms/numbers/list.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getSmsNumbers() .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/numbers/single.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getSmsNumber({ sms_number_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/numbers/update.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.updateSmsNumber({ sms_number_id: 'xxx', paused: false }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/recipients/list.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getSmsRecipients() .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/recipients/single.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getSmsRecipient({ sms_recipient_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/recipients/update.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.updateSmsRecipient({ sms_recipient_id: "xxx", status: "active" }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/sendAnSms.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const SmsParams = require("../../src/SmsParams"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); const to = [ "+18332647501" ]; const smsParams = new SmsParams() .setFrom("+18332647501") .setTo(to) .setText("This is the text content"); mailersend.sendSms(smsParams); ================================================ FILE: examples/v1/sms/smsPersonalization.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const SmsParams = require("../../src/SmsParams"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); const to = [ "+18332647501", "+18332647502" ]; const personalization = [ { "phone_number": "+18332647501", "data": { "name": "Dummy" } }, { "phone_number": "+18332647502", "data": { "name": "Not Dummy" } } ]; const smsParams = new SmsParams() .setFrom("+18332647501") .setTo(to) .setPersonalization(personalization) .setText("Hey {{name}} welcome to our organization"); mailersend.sendSms(smsParams); ================================================ FILE: examples/v1/sms/webhooks/create.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.createSmsWebhook({ sms_number_id: "xxx", name: "Webhook", url: "https:://yourapp.com/hook", enabled: ["sms.sent", "sms.delivered", "sms.failed"], enabled: true }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/webhooks/delete.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.deleteSmsWebhook({ sms_webhook_id: 'xxx' }); ================================================ FILE: examples/v1/sms/webhooks/list.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getSmsWebhooks({ sms_number_id: 'xxx', limit: 10 }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/webhooks/single.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getSmsWebhook({ sms_webhook_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/webhooks/update.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.updateSmsWebhook({ sms_webhook_id: "xxx", name: "Webhook", url: "https:://yourapp.com/hook", enabled: ["sms.sent", "sms.delivered", "sms.failed"], enabled: true }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/templates/delete.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.deleteTemplate({ template_id: 'xxx' }); ================================================ FILE: examples/v1/templates/list.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.templateList() .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/templates/single.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.template({ template_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/tokens/createToken.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.createToken({ name: "Token name", domain_id: "xxx", scopes: [ "email_full", "domains_read", "domains_full", "activity_read", "activity_full", "analytics_read", "analytics_full", "tokens_full", ] }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/tokens/deleteToken.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.deleteToken({ token_id: "xxx" }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/tokens/updateToken.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.updateToken({ token_id: "xxx", status: "pause" }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/webhooks/create.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.createWebhook({ url: "https://example.com", name: "Webhook name", events: ["activity.sent"], domain_id: "xxx" }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/webhooks/delete.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.deleteWebhook({ webhook_id: 'xxx' }); ================================================ FILE: examples/v1/webhooks/list.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.webhooksList({ domain_id: "xxx" }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/webhooks/single.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.webhook({ webhook_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/webhooks/update.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.updateWebhook({ webhook_id: "xxx", name: "New name" }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v2/email/activity/list.js ================================================ 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] } mailerSend.email.activity.domain("domain_id", queryParams) .then((response) => console.log(response.body)) .catch((error) => console.log(error)); ================================================ FILE: examples/v2/email/advancedPersonalization.js ================================================ import 'dotenv/config'; import { MailerSend, EmailParams, Sender, Recipient } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const sentFrom = new Sender("you@yourdomain.com", "Your name"); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const personalization = [ { email: "your@client.com", 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); ================================================ FILE: examples/v2/email/analytics/byCountry.js ================================================ 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); }); ================================================ FILE: examples/v2/email/analytics/byDate.js ================================================ import 'dotenv/config'; import { ActivityEventType, MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.analytics.byDate({ date_from: 1443651141, date_to: 2443651141, event: [ActivityEventType.CLICKED, ActivityEventType.OPENED], }).then(response => { console.log(response.body); }).catch(error => { console.log(error.body); }); ================================================ FILE: examples/v2/email/analytics/byReadingEnvironment.js ================================================ 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); }); ================================================ FILE: examples/v2/email/analytics/byUserAgent.js ================================================ 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); }); ================================================ FILE: examples/v2/email/ccBccRecipients.js ================================================ import 'dotenv/config'; import { MailerSend, EmailParams, Sender, Recipient } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const sentFrom = new Sender("bbbb@yourdomain.com", "Your name"); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const cc = [ new Recipient("your_cc@client.com", "Your Client CC") ]; const bcc = [ new Recipient("your_bcc@client.com", "Your Client BCC") ]; const emailParams = new EmailParams() .setFrom(sentFrom) .setTo(recipients) .setCc(cc) .setBcc(bcc) .setSubject("This is a Subject") .setHtml("This is the HTML content") .setText("This is the text content"); await mailerSend.email.send(emailParams); ================================================ FILE: examples/v2/email/domains/add.js ================================================ import 'dotenv/config'; import { MailerSend, Domain } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const domain = new Domain({ name: "example.com", returnPathSubdomain: "rp_subdomain", customTrackingSubdomain: "ct_subdomain", inboundRoutingSubdomain: "ir_subdomain", }) mailerSend.email.domain.create(domain) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/domains/delete.js ================================================ 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)); ================================================ FILE: examples/v2/email/domains/dns.js ================================================ 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)); ================================================ FILE: examples/v2/email/domains/list.js ================================================ 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)); ================================================ FILE: examples/v2/email/domains/recipients.js ================================================ 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)); ================================================ FILE: examples/v2/email/domains/settings.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.domain.updateSettings("domain_id", { send_paused: 1, track_clicks: 1, track_opens: 1, track_unsubscribe: 1, track_unsubscribe_html: " Unsubscribe now ", track_unsubscribe_plain: "Unsubscribe now", track_content: 1, custom_tracking_enabled: 1, custom_tracking_subdomain: "subdomain", precedence_bulk: 1, ignore_duplicated_recipients: 1, }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/domains/single.js ================================================ 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)); ================================================ FILE: examples/v2/email/domains/verify.js ================================================ 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)); ================================================ FILE: examples/v2/email/getBulkEmailRequestStatus.js ================================================ 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); }); ================================================ FILE: examples/v2/email/identities/create.js ================================================ import 'dotenv/config'; import { MailerSend, Identity } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const identity = new Identity() .setDomainId('domain_id') .setEmail('identity@yourdomain.com') .setName('Name') .setReplyToEmail('reply_identity@yourdomain.com') .setReplyToName('Reply Name') .setAddNote(false); mailerSend.email.identity.create(identity) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/identities/delete.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.identity.delete("identity_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/identities/deleteByEmail.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.identity.deleteByEmail('email_address') .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/identities/list.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.identity.list() .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/identities/single.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.identity.single("identity_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/identities/singleByEmail.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.identity.singleByEmail('email_address') .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/identities/update.js ================================================ import 'dotenv/config'; import { MailerSend, Inbound, InboundFilterType } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const data = { domain_id: 'string', email: 'email@yourdomain.com', name: 'name', personal_note: 'Personal note', reply_to_name: 'Reply Name', reply_to_email: 'repy@yourdomain.com', add_note: true, }; mailerSend.email.identity.update('identiy_id', data) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/identities/updateByEmail.js ================================================ import 'dotenv/config'; import { MailerSend, Inbound, InboundFilterType } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const data = { domain_id: 'string', email: 'email@yourdomain.com', name: 'name', personal_note: 'Personal note', reply_to_name: 'Reply Name', reply_to_email: 'repy@yourdomain.com', add_note: true, }; mailerSend.email.identity.updateByEmail('email_address', data) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/inbounds/create.js ================================================ 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') .setInboundPriority(100) .setMatchFilter({ type: InboundFilterType.MATCH_ALL, }) .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)); ================================================ FILE: examples/v2/email/inbounds/delete.js ================================================ 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)); ================================================ FILE: examples/v2/email/inbounds/list.js ================================================ 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)); ================================================ FILE: examples/v2/email/inbounds/single.js ================================================ 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)); ================================================ FILE: examples/v2/email/inbounds/update.js ================================================ import 'dotenv/config'; import { MailerSend, Inbound, InboundFilterType } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const inbound = new Inbound('inbound test 2', false, 'domain_id') .setMatchFilter({ type: InboundFilterType.MATCH_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)); ================================================ FILE: examples/v2/email/messages/list.js ================================================ 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)); ================================================ FILE: examples/v2/email/messages/single.js ================================================ 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)); ================================================ FILE: examples/v2/email/recipients/addRecipientsToBlocklist.js ================================================ 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: [ "test@example.com" ] }, BlockListType.BLOCK_LIST) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/recipients/addRecipientsToHardBounceList.js ================================================ 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: [ "test@example.com" ] }, BlockListType.HARD_BOUNCES_LIST) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/recipients/addRecipientsToSpamComplaintList.js ================================================ 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: [ "test@example.com" ] }, BlockListType.SPAM_COMPLAINTS_LIST) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/recipients/addRecipientsToUnsubscribeList.js ================================================ 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: [ "test@example.com" ] }, BlockListType.UNSUBSCRIBES_LIST) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/recipients/delete.js ================================================ 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)); ================================================ FILE: examples/v2/email/recipients/deleteAllBlocklistRecipients.js ================================================ 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)); ================================================ FILE: examples/v2/email/recipients/deleteRecipientsFromBlocklist.js ================================================ 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)); ================================================ FILE: examples/v2/email/recipients/deleteRecipientsFromHardBounceList.js ================================================ 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)); ================================================ FILE: examples/v2/email/recipients/deleteRecipientsFromSpamComplaintList.js ================================================ 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)); ================================================ FILE: examples/v2/email/recipients/deleteRecipientsFromUnsubscribeList.js ================================================ 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)); ================================================ FILE: examples/v2/email/recipients/getRecipientsFromBlocklist.js ================================================ 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)); ================================================ FILE: examples/v2/email/recipients/getRecipientsFromHardBounceList.js ================================================ 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)); ================================================ FILE: examples/v2/email/recipients/getRecipientsFromSpamComplaintList.js ================================================ 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)); ================================================ FILE: examples/v2/email/recipients/getRecipientsFromUnsubscribeList.js ================================================ 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)); ================================================ FILE: examples/v2/email/recipients/list.js ================================================ 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)); ================================================ FILE: examples/v2/email/recipients/single.js ================================================ 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)); ================================================ FILE: examples/v2/email/scheduled/delete.js ================================================ 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)); ================================================ FILE: examples/v2/email/scheduled/list.js ================================================ import 'dotenv/config'; import { MailerSend} from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.schedule.list() .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/scheduled/single.js ================================================ 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)); ================================================ FILE: examples/v2/email/sendAnEmail.js ================================================ import 'dotenv/config'; import { MailerSend, EmailParams, Sender, Recipient } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const sentFrom = new Sender("you@yourdomain.com", "Your name"); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const emailParams = new EmailParams() .setFrom(sentFrom) .setTo(recipients) .setReplyTo(sentFrom) .setSubject("This is a Subject") .setHtml("This is the HTML content") .setText("This is the text content"); await mailerSend.email.send(emailParams); ================================================ FILE: examples/v2/email/sendBulkEmail.js ================================================ import 'dotenv/config'; import { MailerSend, EmailParams, Sender, Recipient } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const sentFrom = new Sender("your@yourdomain.com", "Your name"); const bulkEmails = []; const emailParams = new EmailParams() .setFrom(sentFrom) .setTo([ new Recipient("your@client.com", "Your Client") ]) .setSubject("This is a Subject") .setHtml("This is the HTML content") .setText("This is the text content"); bulkEmails.push(emailParams); const emailParams2 = new EmailParams() .setFrom(sentFrom) .setTo([ new Recipient("your_2@client.com", "Your Client 2") ]) .setSubject("This is a Subject 2") .setHtml("This is the HTML content 2") .setText("This is the text content 2"); bulkEmails.push(emailParams2); await mailerSend.email.sendBulk(bulkEmails); ================================================ FILE: examples/v2/email/sendScheduleEmail.js ================================================ import 'dotenv/config'; import { MailerSend, EmailParams, Sender, Recipient } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const sentFrom = new Sender("you@yourdomain.com", "Your name"); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const emailParams = new EmailParams() .setFrom(sentFrom) .setTo(recipients) .setReplyTo(sentFrom) .setSubject("This is a scheduled Subject") .setHtml("This is a scheduled HTML content") .setText("This is a scheduled text content") .setSendAt(Math.floor((new Date(Date.now()+ 30*60*1000)).getTime() / 1000)); //send in 30mins NB:param has to be a Unix timestamp e.g 2443651141 await mailerSend.email.send(emailParams); ================================================ FILE: examples/v2/email/simplePersonalization.js ================================================ import 'dotenv/config'; import { MailerSend, EmailParams, Sender, Recipient } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const sentFrom = new Sender("you@yourdomain.com", "Your name"); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const variables = [ { email: "your@client.com", substitutions: [ { var: 'test', value: 'Test Value' } ], } ]; const emailParams = new EmailParams() .setFrom(sentFrom) .setTo(recipients) .setReplyTo(sentFrom) .setVariables(variables) .setSubject("Subject, {$test}") .setHtml("This is the HTML content, {$test}") .setText("This is the text content, {$test}"); await mailerSend.email.send(emailParams); ================================================ FILE: examples/v2/email/templatedEmail.js ================================================ import 'dotenv/config'; import { MailerSend, EmailParams, Sender, Recipient } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const sentFrom = new Sender("you@yourdomain.com", "Your name"); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const emailParams = new EmailParams() .setFrom(sentFrom) .setTo(recipients) .setReplyTo(sentFrom) .setSubject("This is a Subject") .setTemplateId('templateId'); await mailerSend.email.send(emailParams); ================================================ FILE: examples/v2/email/templates/delete.js ================================================ import 'dotenv/config'; import { MailerSend} from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.template.single("domain_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/templates/list.js ================================================ 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)); ================================================ FILE: examples/v2/email/templates/single.js ================================================ import 'dotenv/config'; import { MailerSend} from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.template.single("domain_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/webhooks/create.js ================================================ 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)); ================================================ FILE: examples/v2/email/webhooks/delete.js ================================================ 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)); ================================================ FILE: examples/v2/email/webhooks/list.js ================================================ 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)); ================================================ FILE: examples/v2/email/webhooks/single.js ================================================ 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)); ================================================ FILE: examples/v2/email/webhooks/update.js ================================================ 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 2") .setEnabled(false) .setEvents([EmailWebhookEventType.SENT, EmailWebhookEventType.OPENED]); mailerSend.email.webhook.update("webhook_id", emailWebhook) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/withAttachment.js ================================================ 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("you@yourdomain.com", "Your name"); const recipients = [ new Recipient("your@client.com", "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("This is the HTML content") .setText("This is the text content"); await mailerSend.email.send(emailParams); ================================================ FILE: examples/v2/email-verification/create.js ================================================ import 'dotenv/config'; import { EmailVerification, MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const emailVerification = new EmailVerification() .setName("List example") .setEmails([ "info@mailersend.com", "test@mailersend.com" ]); mailerSend.emailVerification.create(emailVerification) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email-verification/list.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.emailVerification.list({ limit: 10, page: 1 }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email-verification/results.js ================================================ import 'dotenv/config'; import { EmailVerificationResultType, MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.emailVerification.getListResult("email_verification_id",{ limit: 10, page: 1, result: [EmailVerificationResultType.CATCH_ALL, EmailVerificationResultType.DISPOSABLE] }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email-verification/single.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.emailVerification.single("email_verification_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email-verification/verifyEmail.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.emailVerification.verifyEmail("client@domain.com") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email-verification/verifyList.js ================================================ 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)); ================================================ FILE: examples/v2/others/getApiQuota.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.others.getApiQuota() .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/activities/list.js ================================================ import 'dotenv/config'; import { MailerSend, SmsActivityStatusType } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.activity.list({ sms_number_id: "number_id", status: [SmsActivityStatusType.SENT, SmsActivityStatusType.DELIVERED], limit: 10, page: 1 }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/activities/single.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.activity.single("sms_message_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/inbounds/create.js ================================================ import 'dotenv/config'; import { MailerSend, SmsInbound } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const smsInbound = new SmsInbound() .setSmsNumberId("sms_number_id") .setEnabled(true) .setName("Inbound Name") .setForwardUrl("yourapp.com/hook") .setFilter({ comparer: "equal", value: "START" }); mailerSend.sms.inbound.create(smsInbound) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/inbounds/delete.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.inbound.delete("sms_inbound_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/inbounds/list.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.inbound.list({ enabled: 1, sms_number_id: "sms_number_id", limit: 10, page: 1, }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/inbounds/single.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.inbound.single("sms_inbound_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/inbounds/update.js ================================================ import 'dotenv/config'; import { MailerSend, SmsInbound } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const smsInbound = new SmsInbound() .setSmsNumberId("sms_number_id") .setEnabled(true) .setName("Inbound Name Update") .setForwardUrl("yourapp.com/hook") .setFilter({ comparer: "equal", value: "START" }); mailerSend.sms.inbound.update("sms_inbound_id", {...smsInbound}) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/messages/list.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.message.list({ limit: 10, page: 1 }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/messages/single.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.message.single("sms_message_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/numbers/delete.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.number.delete("sms_number_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/numbers/list.js ================================================ 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)); ================================================ FILE: examples/v2/sms/numbers/single.js ================================================ 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)); ================================================ FILE: examples/v2/sms/numbers/update.js ================================================ 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)); ================================================ FILE: examples/v2/sms/recipients/list.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.recipient.list({ sms_number_id: "sms_number_id", status: "active", limit: 10, page: 1, }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/recipients/single.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.recipient.single("sms_recipient_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/recipients/update.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.recipient.list({ sms_number_id: "sms_number_id", status: "active", limit: 10, page: 1, }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/sendAnSms.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const SmsParams = require("../../src/SmsParams"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); const to = [ "+18332647501" ]; const smsParams = new SmsParams() .setFrom("+18332647501") .setTo(to) .setText("This is the text content"); mailersend.sendSms(smsParams); ================================================ FILE: examples/v2/sms/smsPersonalization.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const SmsParams = require("../../src/SmsParams"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); const to = [ "+18332647501", "+18332647502" ]; const personalization = [ { "phone_number": "+18332647501", "data": { "name": "Dummy" } }, { "phone_number": "+18332647502", "data": { "name": "Not Dummy" } } ]; const smsParams = new SmsParams() .setFrom("+18332647501") .setTo(to) .setPersonalization(personalization) .setText("Hey {{name}} welcome to our organization"); mailersend.sendSms(smsParams); ================================================ FILE: examples/v2/sms/webhooks/create.js ================================================ import 'dotenv/config'; import { MailerSend, SmsWebhook, SmsWebhookEventType } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const smsWebhook = new SmsWebhook() .setName("Sms Webhook") .setUrl("https:://yourapp.com/hook") .setSmsNumberId("sms_number_id") .setEnabled(true) .setEvents([SmsWebhookEventType.SENT, SmsWebhookEventType.DELIVERED]) mailerSend.sms.webhook.create(smsWebhook) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/webhooks/delete.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.webhook.delete("sms_webhook_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/webhooks/list.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.webhook.list("sms_number_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/webhooks/single.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.webhook.single("sms_webhook_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/webhooks/update.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.webhook.update("sms_webhook_id", { name: "Webhook", url: "https:://yourapp.com/hook", enabled: ["sms.sent", "sms.delivered", "sms.failed"], enabled: true }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/tokens/createToken.js ================================================ import 'dotenv/config'; import { MailerSend, Token} from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const token = new Token() .setName("Token name") .setDomainId("domain_id") .setScopes([ "email_full", "domains_read", "domains_full", "activity_read", "activity_full", "analytics_read", "analytics_full", "tokens_full", ]); mailerSend.token.create(token) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/tokens/deleteToken.js ================================================ 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)); ================================================ FILE: examples/v2/tokens/updateToken.js ================================================ 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)); ================================================ FILE: jestconfig.json ================================================ { "transform": { "^.+\\.(t|j)sx?$": "ts-jest" }, "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", "moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"], "coverageReporters": ["json-summary", "text", "lcov"] } ================================================ FILE: package.json ================================================ { "name": "mailersend", "version": "3.0.0", "description": "Node.js helper module for MailerSend API", "main": "./lib/index.js", "typings": "./lib/index.d.ts", "files": [ "lib/**/*" ], "directories": { "lib": "./lib" }, "repository": { "type": "git", "url": "git+https://github.com/mailersend/mailersend-nodejs.git" }, "keywords": [ "mailersend", "mailersend-ts", "mailer_send", "smtp-sender", "email-sender", "email-api", "transactional-emails", "transactional-sms", "typescript", "mailer-send", "types", "email" ], "author": "MailerSend", "license": "MIT", "bugs": { "url": "https://github.com/mailersend/mailersend-nodejs/issues" }, "homepage": "https://www.mailersend.com/", "scripts": { "build": "tsc", "watch": "tsc --watch", "test": "jest --config jestconfig.json", "prepare": "npm run build", "prepublishOnly": "npm test", "version": "git add -A src", "postversion": "git push && git push --tags" }, "dependencies": { "gaxios": "^7.0.0", "qs": "^6.11.0" }, "devDependencies": { "@types/jest": "^29.0.0", "dotenv": "^17.0.0", "jest": "^29.7.0", "jest-coverage-badges": "^1.1.2", "nock": "^14.0.0", "prettier": "^3.0.0", "ts-jest": "^29.2.6", "typescript": "^5.0.0" } } ================================================ FILE: renovate.json ================================================ { "extends": ["github>mailerlite/renovate-config:base"] } ================================================ FILE: src/__tests__/modules/Activity.test.ts ================================================ import nock from "nock"; import { ActivityModule } from "../../modules/email/Activity.module"; import { ActivityEventType } from "../../models/email/Activity"; describe("Activity Module", () => { const activityModule = new ActivityModule("test_key", "http://test.com"); it("domain", async () => { nock("http://test.com") .get("/activity/test_id") .query({ limit: 20, page: 2, date_from: 1672531200, date_to: 1675209600 }) .reply(200, { key1: "key1_value" }, { header1: "test" }); const getActivities = await activityModule.domain("test_id", { limit: 20, page: 2, date_from: 1672531200, date_to: 1675209600 }); expect(getActivities.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(getActivities.body).toMatchObject({ key1: "key1_value" }); expect(getActivities.statusCode).toBe(200); }); it("domain with event filter", async () => { nock("http://test.com") .get("/activity/test_id") .query({ date_from: 1672531200, date_to: 1675209600, "event[0]": ActivityEventType.QUEUED, "event[1]": ActivityEventType.SENT }) .reply(200, { key1: "key1_value" }, { header1: "test" }); const getActivities = await activityModule.domain("test_id", { date_from: 1672531200, date_to: 1675209600, event: [ActivityEventType.QUEUED, ActivityEventType.SENT] }); expect(getActivities.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(getActivities.body).toMatchObject({ key1: "key1_value" }); expect(getActivities.statusCode).toBe(200); }); it("single", async () => { nock("http://test.com").get("/activities/test_activity_id").reply(200, { key1: "activity_value" }, { header1: "test" }); const result = await activityModule.single("test_activity_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "activity_value" }); expect(result.statusCode).toBe(200); }); }); ================================================ FILE: src/__tests__/modules/Analytics.test.ts ================================================ import nock from "nock"; import { AnalyticsModule } from "../../modules/email/Analytics.module"; import { ActivityEventType } from "../../models/email/Activity"; import { AnalyticsGroupByType } from "../../models"; describe("Analytics Module", () => { const analyticsModule = new AnalyticsModule("test_key", "http://test.com"); const baseParams = { date_from: 1672531200, date_to: 1675209600, domain_id: "test_domain_id" }; it("byDate", async () => { nock("http://test.com").get("/analytics/date").query(baseParams).reply(200, { key1: "date_value" }, { header1: "test" }); const result = await analyticsModule.byDate(baseParams); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "date_value" }); expect(result.statusCode).toBe(200); }); it("byCountry", async () => { nock("http://test.com").get("/analytics/country").query(baseParams).reply(200, { key1: "country_value" }, { header1: "test" }); const result = await analyticsModule.byCountry(baseParams); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "country_value" }); expect(result.statusCode).toBe(200); }); it("byUserAgent", async () => { nock("http://test.com").get("/analytics/ua-name").query(baseParams).reply(200, { key1: "ua_value" }, { header1: "test" }); const result = await analyticsModule.byUserAgent(baseParams); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "ua_value" }); expect(result.statusCode).toBe(200); }); it("byReadingEnvironment", async () => { nock("http://test.com").get("/analytics/ua-type").query(baseParams).reply(200, { key1: "ua_type_value" }, { header1: "test" }); const result = await analyticsModule.byReadingEnvironment(baseParams); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "ua_type_value" }); expect(result.statusCode).toBe(200); }); it("byDate with event and group_by", async () => { const dateParams = { ...baseParams, group_by: AnalyticsGroupByType.DAYS, event: [ActivityEventType.CLICKED, ActivityEventType.OPENED] }; nock("http://test.com").get("/analytics/date").query(dateParams).reply(200, { key1: "date_grouped_value" }, { header1: "test" }); const result = await analyticsModule.byDate(dateParams); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "date_grouped_value" }); expect(result.statusCode).toBe(200); }); it("byDate with tags and recipient_id", async () => { const params = { ...baseParams, tags: ["tag1", "tag2"], recipient_id: ["rcpt_id_1"] }; nock("http://test.com").get("/analytics/date").query(params).reply(200, { key1: "date_value" }, { header1: "test" }); const result = await analyticsModule.byDate(params); expect(result.statusCode).toBe(200); }); it("byCountry with tags and recipient_id", async () => { const params = { ...baseParams, tags: ["tag1"], recipient_id: ["rcpt_id_1"] }; nock("http://test.com").get("/analytics/country").query(params).reply(200, { key1: "country_value" }, { header1: "test" }); const result = await analyticsModule.byCountry(params); expect(result.statusCode).toBe(200); }); it("byUserAgent with tags and recipient_id", async () => { const params = { ...baseParams, tags: ["tag1"], recipient_id: ["rcpt_id_1"] }; nock("http://test.com").get("/analytics/ua-name").query(params).reply(200, { key1: "ua_value" }, { header1: "test" }); const result = await analyticsModule.byUserAgent(params); expect(result.statusCode).toBe(200); }); it("byReadingEnvironment with tags and recipient_id", async () => { const params = { ...baseParams, tags: ["tag1"], recipient_id: ["rcpt_id_1"] }; nock("http://test.com").get("/analytics/ua-type").query(params).reply(200, { key1: "ua_type_value" }, { header1: "test" }); const result = await analyticsModule.byReadingEnvironment(params); expect(result.statusCode).toBe(200); }); }); ================================================ FILE: src/__tests__/modules/BlocklistMonitor.test.ts ================================================ import nock from "nock"; import { BlocklistMonitorModule } from "../../modules/BlocklistMonitor.module"; import { BlocklistMonitor } from "../../models"; describe("Blocklist Monitor Module", () => { const blocklistMonitorModule = new BlocklistMonitorModule("test_key", "http://test.com"); it("list", async () => { const params = { page: 1, limit: 10 }; nock("http://test.com").get("/blocklist-monitoring").query(params).reply(200, { key1: "monitor_list" }, { header1: "test" }); const result = await blocklistMonitorModule.list(params); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "monitor_list" }); expect(result.statusCode).toBe(200); }); it("list with query and ordering", async () => { const params = { query: "example.com", sort_by: "name" as const, order: "asc" as const }; nock("http://test.com").get("/blocklist-monitoring").query(params).reply(200, { key1: "monitor_list" }, { header1: "test" }); const result = await blocklistMonitorModule.list(params); expect(result.statusCode).toBe(200); }); it("single", async () => { nock("http://test.com").get("/blocklist-monitoring/test_monitor_id").reply(200, { key1: "monitor_value" }, { header1: "test" }); const result = await blocklistMonitorModule.single("test_monitor_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "monitor_value" }); expect(result.statusCode).toBe(200); }); it("create", async () => { const monitor = new BlocklistMonitor("example.com"); nock("http://test.com").post("/blocklist-monitoring", (body: any) => body.address === "example.com").reply(201, { key1: "monitor_created" }, { header1: "test" }); const result = await blocklistMonitorModule.create(monitor); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "monitor_created" }); expect(result.statusCode).toBe(201); }); it("create with all fields", async () => { const monitor = new BlocklistMonitor("example.com") .setName("My Monitor") .setNotify(true) .setNotifyEmail("alerts@example.com") .setNotifyAddress("https://example.com/webhook"); nock("http://test.com") .post("/blocklist-monitoring", (body: any) => body.address === "example.com" && body.name === "My Monitor" && body.notify === true && body.notify_email === "alerts@example.com" && body.notify_address === "https://example.com/webhook" ) .reply(201, { key1: "monitor_created" }, { header1: "test" }); const result = await blocklistMonitorModule.create(monitor); expect(result.statusCode).toBe(201); }); it("update", async () => { const data = { name: "Updated Monitor" }; nock("http://test.com").put("/blocklist-monitoring/test_monitor_id", (body: any) => body.name === "Updated Monitor").reply(200, { key1: "monitor_updated" }, { header1: "test" }); const result = await blocklistMonitorModule.update("test_monitor_id", data); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "monitor_updated" }); expect(result.statusCode).toBe(200); }); it("update with notify fields", async () => { nock("http://test.com") .put("/blocklist-monitoring/test_monitor_id", (body: any) => body.notify === true && body.notify_email === "alerts@example.com" && body.notify_address === "https://example.com/webhook" ) .reply(200, { key1: "monitor_updated" }, { header1: "test" }); const result = await blocklistMonitorModule.update("test_monitor_id", { notify: true, notify_email: "alerts@example.com", notify_address: "https://example.com/webhook", }); expect(result.statusCode).toBe(200); }); it("delete", async () => { nock("http://test.com").delete("/blocklist-monitoring/test_monitor_id").reply(204, {}, { header1: "test" }); const result = await blocklistMonitorModule.delete("test_monitor_id"); expect(result.statusCode).toBe(204); }); }); ================================================ FILE: src/__tests__/modules/Dmarc.test.ts ================================================ import nock from "nock"; import { DmarcModule } from "../../modules/Dmarc.module"; import { Dmarc } from "../../models"; describe("Dmarc Module", () => { const dmarcModule = new DmarcModule("test_key", "http://test.com"); it("list", async () => { const params = { limit: 20, page: 2 }; nock("http://test.com").get("/dmarc-monitoring").query(params).reply(200, { key1: "key1_value" }, { header1: "test" }); const response = await dmarcModule.list(params); expect(response.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(response.body).toMatchObject({ key1: "key1_value" }); expect(response.statusCode).toBe(200); }); it("list with query and ordering", async () => { const params = { query: "example.com", sort_by: "created_at" as const, order: "desc" as const }; nock("http://test.com").get("/dmarc-monitoring").query(params).reply(200, { key1: "key1_value" }, { header1: "test" }); const response = await dmarcModule.list(params); expect(response.statusCode).toBe(200); }); it("create", async () => { const dmarc = new Dmarc("domain_id_123"); nock("http://test.com").post("/dmarc-monitoring").reply(201, { id: "monitor_id_123" }, { header1: "test" }); const response = await dmarcModule.create(dmarc); expect(response.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(response.body).toMatchObject({ id: "monitor_id_123" }); expect(response.statusCode).toBe(201); }); it("update", async () => { nock("http://test.com").put("/dmarc-monitoring/test_id").reply(200, { key1: "key1_value" }, { header1: "test" }); const response = await dmarcModule.update("test_id", { wanted_dmarc_record: "v=DMARC1; p=reject;" }); expect(response.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(response.body).toMatchObject({ key1: "key1_value" }); expect(response.statusCode).toBe(200); }); it("delete", async () => { nock("http://test.com").delete("/dmarc-monitoring/test_id").reply(204, {}, { header1: "test" }); const response = await dmarcModule.delete("test_id"); expect(response.statusCode).toBe(204); }); it("report", async () => { const params = { limit: 10, page: 1 }; nock("http://test.com").get("/dmarc-monitoring/test_id/report").query(params).reply(200, { key1: "key1_value" }, { header1: "test" }); const response = await dmarcModule.report("test_id", params); expect(response.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(response.body).toMatchObject({ key1: "key1_value" }); expect(response.statusCode).toBe(200); }); it("report with filters", async () => { const params = { date_from: "2024-01-01", date_to: "2024-01-31", search: "192.0.2.1", category: "fail", report_source: "google.com" }; nock("http://test.com").get("/dmarc-monitoring/test_id/report").query(params).reply(200, { key1: "key1_value" }, { header1: "test" }); const response = await dmarcModule.report("test_id", params); expect(response.statusCode).toBe(200); }); it("reportByIp", async () => { const params = { limit: 10, page: 1 }; nock("http://test.com").get("/dmarc-monitoring/test_id/report/1.2.3.4").query(params).reply(200, { key1: "key1_value" }, { header1: "test" }); const response = await dmarcModule.reportByIp("test_id", "1.2.3.4", params); expect(response.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(response.body).toMatchObject({ key1: "key1_value" }); expect(response.statusCode).toBe(200); }); it("reportByIp with filters", async () => { const params = { date_from: "2024-01-01", date_to: "2024-01-31", search: "test", category: "fail", report_source: "google.com" }; nock("http://test.com").get("/dmarc-monitoring/test_id/report/1.2.3.4").query(params).reply(200, { key1: "key1_value" }, { header1: "test" }); const response = await dmarcModule.reportByIp("test_id", "1.2.3.4", params); expect(response.statusCode).toBe(200); }); it("reportSources", async () => { const params = { date_from: "2024-01-01", date_to: "2024-01-31" }; nock("http://test.com").get("/dmarc-monitoring/test_id/report-sources").query(params).reply(200, { key1: "key1_value" }, { header1: "test" }); const response = await dmarcModule.reportSources("test_id", params); expect(response.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(response.body).toMatchObject({ key1: "key1_value" }); expect(response.statusCode).toBe(200); }); it("reportSources with status", async () => { const params = { date_from: "2024-01-01", date_to: "2024-01-31", status: "rejected" as const }; nock("http://test.com").get("/dmarc-monitoring/test_id/report-sources").query(params).reply(200, { key1: "key1_value" }, { header1: "test" }); const response = await dmarcModule.reportSources("test_id", params); expect(response.statusCode).toBe(200); }); it("addFavorite", async () => { nock("http://test.com").put("/dmarc-monitoring/test_id/favorite/1.2.3.4").reply(200, {}, { header1: "test" }); const response = await dmarcModule.addFavorite("test_id", "1.2.3.4"); expect(response.statusCode).toBe(200); }); it("removeFavorite", async () => { nock("http://test.com").delete("/dmarc-monitoring/test_id/favorite/1.2.3.4").reply(204, {}, { header1: "test" }); const response = await dmarcModule.removeFavorite("test_id", "1.2.3.4"); expect(response.statusCode).toBe(204); }); }); ================================================ FILE: src/__tests__/modules/Domain.test.ts ================================================ import nock from "nock"; import { DomainModule } from "../../modules/email/Domain.module"; import { Domain } from "../../models"; describe("Domain Module", () => { const domainModule = new DomainModule("test_key", "http://test.com"); it("create", async () => { const domain = new Domain("mydomain.com", "rp_subdomain", "ct_subdomain", "ir_subdomain"); nock("http://test.com") .post("/domains", { name: "mydomain.com", return_path_subdomain: "rp_subdomain", custom_tracking_subdomain: "ct_subdomain", inbound_routing_subdomain: "ir_subdomain", }) .reply( 200, { id: "dle1krod2jvn8gwm", name: "mydomain.com", }, { header1: "test" }, ); const createDomain = await domainModule.create(domain); expect(createDomain.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(createDomain.body).toMatchObject({ id: "dle1krod2jvn8gwm", name: "mydomain.com" }); expect(createDomain.statusCode).toBe(200); }); it("create with only name", async () => { const domain = new Domain("mydomain.com"); nock("http://test.com") .post("/domains", { name: "mydomain.com" }) .reply(200, { id: "dle1krod2jvn8gwm", name: "mydomain.com" }, { header1: "test" }); const createDomain = await domainModule.create(domain); expect(createDomain.body).toMatchObject({ id: "dle1krod2jvn8gwm", name: "mydomain.com" }); expect(createDomain.statusCode).toBe(200); }); it("list", async () => { const params = { limit: 20, page: 2, verified: true }; nock("http://test.com").get("/domains").query(params).reply(200, { key1: "key1_value" }, { header1: "test" }); const getDomains = await domainModule.list(params); expect(getDomains.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(getDomains.body).toMatchObject({ key1: "key1_value" }); expect(getDomains.statusCode).toBe(200); }); it("recipients", async () => { const params = { limit: 20, page: 2 }; nock("http://test.com") .get("/domains/test_id/recipients") .query(params) .reply(200, { key1: "key1_value" }, { header1: "test" }); const getDomains = await domainModule.recipients("test_id", params); expect(getDomains.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(getDomains.body).toMatchObject({ key1: "key1_value" }); expect(getDomains.statusCode).toBe(200); }); it("single", async () => { nock("http://test.com").get("/domains/test_id").reply(200, { key1: "key1_value" }, { header1: "test" }); const getDomain = await domainModule.single("test_id"); expect(getDomain.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(getDomain.body).toMatchObject({ key1: "key1_value" }); expect(getDomain.statusCode).toBe(200); }); it("settings", async () => { nock("http://test.com") .put("/domains/test_id/settings", { send_paused: true, track_clicks: true, track_unsubscribe_html: "html here", }) .reply(200, { key1: "key1_value" }, { header1: "test" }); const updateSettings = await domainModule.updateSettings("test_id", { send_paused: true, track_clicks: true, track_unsubscribe_html: "html here", }); expect(updateSettings.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(updateSettings.body).toMatchObject({ key1: "key1_value" }); expect(updateSettings.statusCode).toBe(200); }); it("settings with all remaining fields", async () => { nock("http://test.com") .put("/domains/test_id/settings", { track_opens: true, track_unsubscribe: true, 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: "track_subdomain", precedence_bulk: true, ignore_duplicated_recipients: true, }) .reply(200, { key1: "key1_value" }, { header1: "test" }); const updateSettings = await domainModule.updateSettings("test_id", { track_opens: true, track_unsubscribe: true, 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: "track_subdomain", precedence_bulk: true, ignore_duplicated_recipients: true, }); expect(updateSettings.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(updateSettings.body).toMatchObject({ key1: "key1_value" }); expect(updateSettings.statusCode).toBe(200); }); it("delete", async () => { nock("http://test.com").delete("/domains/test_id").reply(204); const deleteDomain = await domainModule.delete("test_id"); expect(deleteDomain.statusCode).toBe(204); }); it("dns", async () => { nock("http://test.com").get("/domains/test_id/dns-records").reply(200, { key1: "dns" }, { header1: "dns-header" }); const getDNS = await domainModule.dns("test_id"); expect(getDNS.headers).toMatchObject({ header1: "dns-header", "content-type": "application/json" }); expect(getDNS.body).toMatchObject({ key1: "dns" }); expect(getDNS.statusCode).toBe(200); }); it("verify", async () => { nock("http://test.com").get("/domains/test_id/verify").reply(200, { key1: "verify" }, { header1: "verify-header" }); const verifyDomain = await domainModule.verify("test_id"); expect(verifyDomain.headers).toMatchObject({ header1: "verify-header", "content-type": "application/json" }); expect(verifyDomain.body).toMatchObject({ key1: "verify" }); expect(verifyDomain.statusCode).toBe(200); }); }); ================================================ FILE: src/__tests__/modules/Email.test.ts ================================================ import nock from "nock"; import { EmailModule } from "../../modules/Email.module"; import { EmailParams, Recipient, EmailWebhook, EmailWebhookEventType } from "../../models"; import { Attachment } from "../../models/email/Attachment"; import { ActivityModule } from "../../modules/email/Activity.module"; import { AnalyticsModule } from "../../modules/email/Analytics.module"; import { DomainModule } from "../../modules/email/Domain.module"; import { InboundModule } from "../../modules/email/Inbound.module"; import { MessageModule } from "../../modules/email/Message.module"; import { ScheduleModule } from "../../modules/email/Schedule.module"; import { RecipientModule } from "../../modules/email/Recipient.module"; import { TemplateModule } from "../../modules/email/Template.module"; import { EmailWebhookModule } from "../../modules/email/Webhook.module"; describe("Email Module", () => { const emailModule = new EmailModule("test_key", "http://test.com"); it("Constructor", () => { expect(emailModule.activity instanceof ActivityModule).toBe(true); expect(emailModule.analytics instanceof AnalyticsModule).toBe(true); expect(emailModule.domain instanceof DomainModule).toBe(true); expect(emailModule.inbound instanceof InboundModule).toBe(true); expect(emailModule.message instanceof MessageModule).toBe(true); expect(emailModule.schedule instanceof ScheduleModule).toBe(true); expect(emailModule.recipient instanceof RecipientModule).toBe(true); expect(emailModule.template instanceof TemplateModule).toBe(true); expect(emailModule.webhook instanceof EmailWebhookModule).toBe(true); }); it("send email", async () => { nock("http://test.com").post("/email").reply(202, { key1: "key1_value" }, { header1: "test" }); const emailParams = new EmailParams() .setFrom({ email: "some@email.com" }) .setTo([new Recipient("some_recipient@mail.com")]) .setSubject("Some subject") .setText("Some text") .setHtml("Some html"); const sendEmail = await emailModule.send(emailParams); expect(sendEmail.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(sendEmail.body).toMatchObject({ key1: "key1_value" }); expect(sendEmail.statusCode).toBe(202); }); it("send email with personalization", async () => { const personalization = [ { email: "your@client.com", data: { test: { number: 123434, } }, } ]; nock("http://test.com").post("/email").reply(202, { key1: "key1_value" }, { header1: "test" }); const emailParams = new EmailParams() .setFrom({ email: "some@email.com" }) .setTo([new Recipient("some_recipient@mail.com")]) .setSubject("Some subject") .setPersonalization(personalization) .setText("Some text") .setHtml("Some html"); const sendEmail = await emailModule.send(emailParams); expect(sendEmail.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(sendEmail.body).toMatchObject({ key1: "key1_value" }); expect(sendEmail.statusCode).toBe(202); }); it("send email with send_at as unix timestamp", async () => { const sendAt = 1893456000; nock("http://test.com") .post("/email", (body: any) => body.send_at === sendAt) .reply(202, {}, {}); const emailParams = new EmailParams() .setFrom({ email: "some@email.com" }) .setTo([new Recipient("some_recipient@mail.com")]) .setSubject("Some subject") .setText("Some text") .setSendAt(sendAt); const result = await emailModule.send(emailParams); expect(result.statusCode).toBe(202); }); it("send email with send_at as ISO string", async () => { const sendAt = "2030-01-01T12:00:00Z"; nock("http://test.com") .post("/email", (body: any) => body.send_at === sendAt) .reply(202, {}, {}); const emailParams = new EmailParams() .setFrom({ email: "some@email.com" }) .setTo([new Recipient("some_recipient@mail.com")]) .setSubject("Some subject") .setText("Some text") .setSendAt(sendAt); const result = await emailModule.send(emailParams); expect(result.statusCode).toBe(202); }); it("send email with attachments", async () => { const attachment = new Attachment("base64content", "file.pdf", "attachment", "attach_id"); nock("http://test.com") .post("/email", (body: any) => { const a = body.attachments[0]; return a.content === "base64content" && a.filename === "file.pdf" && a.disposition === "attachment" && a.id === "attach_id"; }) .reply(202, {}, {}); const emailParams = new EmailParams() .setFrom({ email: "some@email.com" }) .setTo([new Recipient("some_recipient@mail.com")]) .setSubject("Some subject") .setText("Some text") .setAttachments([attachment]); const result = await emailModule.send(emailParams); expect(result.statusCode).toBe(202); }); it("send email with template_id", async () => { nock("http://test.com") .post("/email", (body: any) => body.template_id === "tmpl_abc123") .reply(202, {}, {}); const emailParams = new EmailParams() .setTo([new Recipient("some_recipient@mail.com")]) .setTemplateId("tmpl_abc123"); const result = await emailModule.send(emailParams); expect(result.statusCode).toBe(202); }); it("send email with cc", async () => { const cc = [new Recipient("cc@example.com", "CC Person")]; nock("http://test.com") .post("/email", (body: any) => body.cc[0].email === "cc@example.com" && body.cc[0].name === "CC Person") .reply(202, {}, {}); const emailParams = new EmailParams() .setFrom({ email: "some@email.com" }) .setTo([new Recipient("some_recipient@mail.com")]) .setSubject("Some subject") .setText("Some text") .setCc(cc); const result = await emailModule.send(emailParams); expect(result.statusCode).toBe(202); }); it("send email with bcc", async () => { const bcc = [new Recipient("bcc@example.com", "BCC Person")]; nock("http://test.com") .post("/email", (body: any) => body.bcc[0].email === "bcc@example.com" && body.bcc[0].name === "BCC Person") .reply(202, {}, {}); const emailParams = new EmailParams() .setFrom({ email: "some@email.com" }) .setTo([new Recipient("some_recipient@mail.com")]) .setSubject("Some subject") .setText("Some text") .setBcc(bcc); const result = await emailModule.send(emailParams); expect(result.statusCode).toBe(202); }); it("send email with reply_to", async () => { nock("http://test.com") .post("/email", (body: any) => body.reply_to.email === "reply@example.com" && body.reply_to.name === "Reply Person") .reply(202, {}, {}); const emailParams = new EmailParams() .setFrom({ email: "some@email.com" }) .setTo([new Recipient("some_recipient@mail.com")]) .setSubject("Some subject") .setText("Some text") .setReplyTo(new Recipient("reply@example.com", "Reply Person")); const result = await emailModule.send(emailParams); expect(result.statusCode).toBe(202); }); it("send email with in_reply_to", async () => { nock("http://test.com") .post("/email", (body: any) => body.in_reply_to === "") .reply(202, {}, {}); const emailParams = new EmailParams() .setFrom({ email: "some@email.com" }) .setTo([new Recipient("some_recipient@mail.com")]) .setSubject("Some subject") .setText("Some text") .setInReplyTo(""); const result = await emailModule.send(emailParams); expect(result.statusCode).toBe(202); }); it("send email with references", async () => { const references = ["", ""]; nock("http://test.com") .post("/email", (body: any) => Array.isArray(body.references) && body.references[0] === "" && body.references[1] === "") .reply(202, {}, {}); const emailParams = new EmailParams() .setFrom({ email: "some@email.com" }) .setTo([new Recipient("some_recipient@mail.com")]) .setSubject("Some subject") .setText("Some text") .setReferences(references); const result = await emailModule.send(emailParams); expect(result.statusCode).toBe(202); }); it("send email with tags", async () => { nock("http://test.com") .post("/email", (body: any) => Array.isArray(body.tags) && body.tags[0] === "tag1" && body.tags[1] === "tag2") .reply(202, {}, {}); const emailParams = new EmailParams() .setFrom({ email: "some@email.com" }) .setTo([new Recipient("some_recipient@mail.com")]) .setSubject("Some subject") .setText("Some text") .setTags(["tag1", "tag2"]); const result = await emailModule.send(emailParams); expect(result.statusCode).toBe(202); }); it("send email with headers", async () => { nock("http://test.com") .post("/email", (body: any) => body.headers[0].name === "X-Custom" && body.headers[0].value === "custom-value") .reply(202, {}, {}); const emailParams = new EmailParams() .setFrom({ email: "some@email.com" }) .setTo([new Recipient("some_recipient@mail.com")]) .setSubject("Some subject") .setText("Some text") .setHeaders([{ name: "X-Custom", value: "custom-value" }]); const result = await emailModule.send(emailParams); expect(result.statusCode).toBe(202); }); it("send email with settings", async () => { nock("http://test.com") .post("/email", (body: any) => body.settings.track_clicks === true && body.settings.track_opens === false && body.settings.track_content === true) .reply(202, {}, {}); const emailParams = new EmailParams() .setFrom({ email: "some@email.com" }) .setTo([new Recipient("some_recipient@mail.com")]) .setSubject("Some subject") .setText("Some text") .setSettings({ track_clicks: true, track_opens: false, track_content: true }); const result = await emailModule.send(emailParams); expect(result.statusCode).toBe(202); }); it("send email with precedence_bulk", async () => { nock("http://test.com") .post("/email", (body: any) => body.precedence_bulk === true) .reply(202, {}, {}); const emailParams = new EmailParams() .setFrom({ email: "some@email.com" }) .setTo([new Recipient("some_recipient@mail.com")]) .setSubject("Some subject") .setText("Some text") .setPrecedenceBulk(true); const result = await emailModule.send(emailParams); expect(result.statusCode).toBe(202); }); it("send email with list_unsubscribe", async () => { nock("http://test.com") .post("/email", (body: any) => body.list_unsubscribe === "https://www.example.com/unsubscribe") .reply(202, {}, {}); const emailParams = new EmailParams() .setFrom({ email: "some@email.com" }) .setTo([new Recipient("some_recipient@mail.com")]) .setSubject("Some subject") .setText("Some text") .setListUnsubscribe("https://www.example.com/unsubscribe"); const result = await emailModule.send(emailParams); expect(result.statusCode).toBe(202); }); it("send email with rcpt_to", async () => { nock("http://test.com") .post("/email", (body: any) => body.rcpt_to[0].email === "rcpt@example.com") .reply(202, {}, {}); const emailParams = new EmailParams() .setFrom({ email: "some@email.com" }) .setTo([new Recipient("some_recipient@mail.com")]) .setSubject("Some subject") .setText("Some text") .setRcptTo([new Recipient("rcpt@example.com")]); const result = await emailModule.send(emailParams); expect(result.statusCode).toBe(202); }); it("send bulk", async () => { nock("http://test.com").post("/bulk-email").reply(202, { key1: "key1_value" }, { header1: "test" }); const emailParams = new EmailParams() .setFrom({ email: "some@email.com" }) .setTo([new Recipient("some_recipient@mail.com")]) .setSubject("Some subject") .setText("Some text") .setHtml("Some html"); const sendEmail = await emailModule.sendBulk([emailParams]); expect(sendEmail.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(sendEmail.body).toMatchObject({ key1: "key1_value" }); expect(sendEmail.statusCode).toBe(202); }); it("send bulk email serializes each EmailParams item", async () => { const emailParams1 = new EmailParams() .setFrom({ email: "sender1@example.com" }) .setTo([new Recipient("recipient1@example.com", "Recipient One")]) .setSubject("Subject One") .setText("Body One"); const emailParams2 = new EmailParams() .setFrom({ email: "sender2@example.com" }) .setTo([new Recipient("recipient2@example.com", "Recipient Two")]) .setSubject("Subject Two") .setText("Body Two"); nock("http://test.com") .post("/bulk-email", (body: any) => { return ( Array.isArray(body) && body[0].from.email === "sender1@example.com" && body[0].to[0].email === "recipient1@example.com" && body[0].subject === "Subject One" && body[1].from.email === "sender2@example.com" && body[1].to[0].email === "recipient2@example.com" && body[1].subject === "Subject Two" ); }) .reply(202, { bulk_email_id: "bulk_123" }, {}); const result = await emailModule.sendBulk([emailParams1, emailParams2]); expect(result.statusCode).toBe(202); expect(result.body).toMatchObject({ bulk_email_id: "bulk_123" }); }); it("get bulk", async () => { nock("http://test.com").get("/bulk-email/test_id_bulk").reply(202, { key1: "key1_value" }, { header1: "test" }); const sendEmail = await emailModule.getBulkStatus("test_id_bulk"); expect(sendEmail.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(sendEmail.body).toMatchObject({ key1: "key1_value" }); expect(sendEmail.statusCode).toBe(202); }); }); ================================================ FILE: src/__tests__/modules/EmailVerification.test.ts ================================================ import nock from "nock"; import { EmailVerification, EmailVerificationResultType } from "../../models"; import { EmailVerificationModule } from "../../modules/EmailVerification.module"; describe("Email Verification Module", () => { const emailVerificationModule = new EmailVerificationModule("test_key", "http://test.com"); it("create", async () => { const emailVerification = new EmailVerification("List example", [ "info@mailersend.com", "test@mailersend.com" ]); nock("http://test.com").post("/email-verification").reply( 200, { id: "dle1krod2jvn8gwm", name: "Example List" }, { header1: "test" }, ); const createEmailVerificationList = await emailVerificationModule.create(emailVerification); expect(createEmailVerificationList.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(createEmailVerificationList.body).toMatchObject({ id: "dle1krod2jvn8gwm", name: "Example List" }); expect(createEmailVerificationList.statusCode).toBe(200); }); it("create with list_id and verify", async () => { const emailVerification = new EmailVerification("List example", ["info@mailersend.com"]) .setListId("existing_list_id") .setVerify(true); nock("http://test.com") .post("/email-verification", (body: any) => body.list_id === "existing_list_id" && body.verify === true ) .reply(200, { id: "dle1krod2jvn8gwm" }, { header1: "test" }); const result = await emailVerificationModule.create(emailVerification); expect(result.statusCode).toBe(200); }); it("list", async () => { const params = { limit: 20, page: 2}; nock("http://test.com").get("/email-verification").query(params).reply(200, { key1: "key1_value" }, { header1: "test" }); const getEmailVerifications = await emailVerificationModule.list(params); expect(getEmailVerifications.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(getEmailVerifications.body).toMatchObject({ key1: "key1_value" }); expect(getEmailVerifications.statusCode).toBe(200); }); it("single", async () => { nock("http://test.com").get("/email-verification/test_id").reply(200, { key1: "key1_value" }, { header1: "test" }); const getEmailVerification = await emailVerificationModule.single("test_id"); expect(getEmailVerification.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(getEmailVerification.body).toMatchObject({ key1: "key1_value" }); expect(getEmailVerification.statusCode).toBe(200); }); it("single with query params", async () => { const params = { detailed: true, page: 1, limit: 10 }; nock("http://test.com").get("/email-verification/test_id").query(params).reply(200, { key1: "key1_value" }, { header1: "test" }); const getEmailVerification = await emailVerificationModule.single("test_id", params); expect(getEmailVerification.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(getEmailVerification.body).toMatchObject({ key1: "key1_value" }); expect(getEmailVerification.statusCode).toBe(200); }); it("verify list", async () => { nock("http://test.com").get("/email-verification/test_id/verify").reply(200, { key1: "key1_value" }, { header1: "test" }); const verifyEmailVerification = await emailVerificationModule.verifyList("test_id"); expect(verifyEmailVerification.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(verifyEmailVerification.body).toMatchObject({ key1: "key1_value" }); expect(verifyEmailVerification.statusCode).toBe(200); }); it("get list result", async () => { const params = { limit: 10, page: 1}; nock("http://test.com").get("/email-verification/test_id/results").query(params).reply(200, { key1: "key1_value" }, { header1: "test" }); const getListResult = await emailVerificationModule.getListResult("test_id", params); expect(getListResult.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(getListResult.body).toMatchObject({ key1: "key1_value" }); expect(getListResult.statusCode).toBe(200); }); it("get list result with results filter", async () => { const params = { limit: 10, page: 1, results: [EmailVerificationResultType.CATCH_ALL, EmailVerificationResultType.DISPOSABLE] }; nock("http://test.com").get("/email-verification/test_id/results").query(params).reply(200, { key1: "key1_value" }, { header1: "test" }); const result = await emailVerificationModule.getListResult("test_id", params); expect(result.statusCode).toBe(200); }); it("verify email", async () => { nock("http://test.com").post("/email-verification/verify").reply(200, { message: "valid" }, { header1: "test" }); const verifyEmail = await emailVerificationModule.verifyEmail("email@email.com"); expect(verifyEmail.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(verifyEmail.body).toMatchObject({ message: "valid" }); expect(verifyEmail.statusCode).toBe(200); }); it("verify email async", async () => { nock("http://test.com").post("/email-verification/verify-async").reply(200, { id: "async_job_id" }, { header1: "test" }); const result = await emailVerificationModule.verifyEmailAsync("email@email.com"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ id: "async_job_id" }); expect(result.statusCode).toBe(200); }); it("get verify email async status", async () => { nock("http://test.com").get("/email-verification/verify-async/async_job_id").reply(200, { status: "completed" }, { header1: "test" }); const result = await emailVerificationModule.getVerifyEmailAsyncStatus("async_job_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ status: "completed" }); expect(result.statusCode).toBe(200); }); }); ================================================ FILE: src/__tests__/modules/Identity.test.ts ================================================ import nock from "nock"; import { IdentityModule } from "../../modules/email/Identity.module"; import { Identity } from "../../models"; describe("Identity Module", () => { const identityModule = new IdentityModule("test_key", "http://test.com"); const identity = new Identity("domain_id", "sender@example.com", "Sender Name"); it("create", async () => { nock("http://test.com").post("/identities").reply(201, { key1: "identity_created" }, { header1: "test" }); const result = await identityModule.create(identity); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "identity_created" }); expect(result.statusCode).toBe(201); }); it("list", async () => { const params = { domain_id: "domain_id", page: 1, limit: 10 }; nock("http://test.com").get("/identities").query(params).reply(200, { key1: "identity_list" }, { header1: "test" }); const result = await identityModule.list(params); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "identity_list" }); expect(result.statusCode).toBe(200); }); it("list with query and ordering", async () => { const params = { query: "sender", order_by: "email" as const, order: "asc" as const }; nock("http://test.com").get("/identities").query(params).reply(200, { key1: "identity_list" }, { header1: "test" }); const result = await identityModule.list(params); expect(result.statusCode).toBe(200); }); it("single", async () => { nock("http://test.com").get("/identities/test_identity_id").reply(200, { key1: "identity_value" }, { header1: "test" }); const result = await identityModule.single("test_identity_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "identity_value" }); expect(result.statusCode).toBe(200); }); it("singleByEmail", async () => { nock("http://test.com").get("/identities/email/sender@example.com").reply(200, { key1: "identity_by_email" }, { header1: "test" }); const result = await identityModule.singleByEmail("sender@example.com"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "identity_by_email" }); expect(result.statusCode).toBe(200); }); it("update", async () => { nock("http://test.com").put("/identities/test_identity_id").reply(200, { key1: "identity_updated" }, { header1: "test" }); const result = await identityModule.update("test_identity_id", { name: "New Name" }); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "identity_updated" }); expect(result.statusCode).toBe(200); }); it("updateByEMail", async () => { nock("http://test.com").put("/identities/email/sender@example.com").reply(200, { key1: "identity_updated_by_email" }, { header1: "test" }); const result = await identityModule.updateByEMail("sender@example.com", { name: "New Name" }); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "identity_updated_by_email" }); expect(result.statusCode).toBe(200); }); it("delete", async () => { nock("http://test.com").delete("/identities/test_identity_id").reply(204, {}, { header1: "test" }); const result = await identityModule.delete("test_identity_id"); expect(result.statusCode).toBe(204); }); it("deleteByEmail", async () => { nock("http://test.com").delete("/identities/email/sender@example.com").reply(202, {}, { header1: "test" }); const result = await identityModule.deleteByEmail("sender@example.com"); expect(result.statusCode).toBe(202); }); it("resend", async () => { nock("http://test.com").post("/identities/test_identity_id/resend").reply(200, { key1: "identity_resent" }, { header1: "test" }); const result = await identityModule.resend("test_identity_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "identity_resent" }); expect(result.statusCode).toBe(200); }); }); ================================================ FILE: src/__tests__/modules/Inbound.test.ts ================================================ import nock from "nock"; import { InboundModule } from "../../modules/email/Inbound.module"; import { Inbound, InboundUpdateParams, InboundFilterType, ComparerType } from "../../models"; describe("Inbound Module", () => { const inboundModule = new InboundModule("test_key", "http://test.com"); const inbound = new Inbound("test inbound", true, "domain_id"); it("create sends POST to /inbound with required fields", async () => { nock("http://test.com") .post("/inbound", (body) => { return body.name === "test inbound" && body.domain_enabled === true && body.domain_id === "domain_id"; }) .reply(201, { key1: "inbound_created" }, { header1: "test" }); const result = await inboundModule.create(inbound); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "inbound_created" }); expect(result.statusCode).toBe(201); }); it("create sends POST to /inbound with all optional fields", async () => { const fullInbound = new Inbound("full inbound", true, "domain_id_full") .setInboundDomain("inbound.example.com") .setInboundPriority(50) .setForwards([{ type: "webhook", value: "https://example.com/hook" }]) .setMatchFilter({ type: InboundFilterType.MATCH_SENDER, filters: [{ comparer: ComparerType.EQUAL, value: "sender@example.com" }], }) .setCatchFilter({ type: InboundFilterType.CATCH_RECIPIENT, filters: [{ comparer: ComparerType.EQUAL, value: "recipient@example.com" }], }); nock("http://test.com") .post("/inbound", (body) => { return body.name === "full inbound" && body.domain_enabled === true && body.domain_id === "domain_id_full" && body.inbound_domain === "inbound.example.com" && body.inbound_priority === 50 && Array.isArray(body.forwards) && body.forwards.length === 1 && body.forwards[0].type === "webhook" && body.forwards[0].value === "https://example.com/hook" && body.match_filter !== undefined && body.catch_filter !== undefined; }) .reply(201, { key1: "inbound_created_full" }, { header1: "test" }); const result = await inboundModule.create(fullInbound); expect(result.statusCode).toBe(201); expect(result.body).toMatchObject({ key1: "inbound_created_full" }); }); it("list sends GET to /inbound with query params", async () => { const params = { domain_id: "domain_id", page: 1, limit: 10 }; nock("http://test.com").get("/inbound").query(params).reply(200, { key1: "inbound_list" }, { header1: "test" }); const result = await inboundModule.list(params); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "inbound_list" }); expect(result.statusCode).toBe(200); }); it("list sends GET to /inbound with no arguments", async () => { nock("http://test.com").get("/inbound").reply(200, { key1: "inbound_list_all" }, { header1: "test" }); const result = await inboundModule.list(); expect(result.statusCode).toBe(200); expect(result.body).toMatchObject({ key1: "inbound_list_all" }); }); it("single sends GET to /inbound/{id}", async () => { nock("http://test.com").get("/inbound/test_inbound_id").reply(200, { key1: "inbound_value" }, { header1: "test" }); const result = await inboundModule.single("test_inbound_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "inbound_value" }); expect(result.statusCode).toBe(200); }); it("update sends PUT to /inbound/{id} with required fields and no domain_id", async () => { const updateParams = new InboundUpdateParams("test inbound", true); nock("http://test.com") .put("/inbound/test_inbound_id", (body) => { return body.name === "test inbound" && body.domain_enabled === true && !Object.prototype.hasOwnProperty.call(body, "domain_id"); }) .reply(200, { key1: "inbound_updated" }, { header1: "test" }); const result = await inboundModule.update("test_inbound_id", updateParams); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "inbound_updated" }); expect(result.statusCode).toBe(200); }); it("update sends PUT to /inbound/{id} with all optional fields", async () => { const updateParams = new InboundUpdateParams("full inbound", false) .setInboundDomain("inbound.example.com") .setInboundPriority(25) .setForwards([{ type: "webhook", value: "https://example.com/hook" }]) .setMatchFilter({ type: InboundFilterType.MATCH_ALL, }) .setCatchFilter({ type: InboundFilterType.CATCH_ALL, }); nock("http://test.com") .put("/inbound/test_inbound_id", (body) => { return body.name === "full inbound" && body.domain_enabled === false && !Object.prototype.hasOwnProperty.call(body, "domain_id") && body.inbound_domain === "inbound.example.com" && body.inbound_priority === 25 && Array.isArray(body.forwards) && body.forwards.length === 1 && body.match_filter !== undefined && body.catch_filter !== undefined; }) .reply(200, { key1: "inbound_updated_full" }, { header1: "test" }); const result = await inboundModule.update("test_inbound_id", updateParams); expect(result.statusCode).toBe(200); expect(result.body).toMatchObject({ key1: "inbound_updated_full" }); }); it("delete sends DELETE to /inbound/{id} and returns 204", async () => { nock("http://test.com").delete("/inbound/test_inbound_id").reply(204, {}, { header1: "test" }); const result = await inboundModule.delete("test_inbound_id"); expect(result.statusCode).toBe(204); }); }); ================================================ FILE: src/__tests__/modules/MailerSend.test.ts ================================================ import { MailerSend } from "../../modules/MailerSend.module"; import { EmailModule } from "../../modules/Email.module"; import { SMSModule } from "../../modules/SMS.module"; import { TokenModule } from "../../modules/Token.module"; import { EmailVerificationModule } from "../../modules/EmailVerification.module"; describe("MailerSend module", () => { it("Constructor", () => { const mailerSend = new MailerSend({ apiKey: "your_api_key" }); expect(mailerSend.sms instanceof SMSModule).toBe(true); expect(mailerSend.email instanceof EmailModule).toBe(true); expect(mailerSend.token instanceof TokenModule).toBe(true); expect(mailerSend.emailVerification instanceof EmailVerificationModule).toBe(true); }); }); ================================================ FILE: src/__tests__/modules/Message.test.ts ================================================ import nock from "nock"; import { MessageModule } from "../../modules/email/Message.module"; describe("Message Module", () => { const messageModule = new MessageModule("test_key", "http://test.com"); it("list", async () => { nock("http://test.com") .get("/messages") .query({ limit: 20, page: 2 }) .reply(200, { key1: "key1_value" }, { header1: "test" }); const getMessages = await messageModule.list({ limit: 20, page: 2 }); expect(getMessages.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(getMessages.body).toMatchObject({ key1: "key1_value" }); expect(getMessages.statusCode).toBe(200); }); it("single", async () => { nock("http://test.com").get("/messages/test_id").reply(200, { key1: "key1_value" }, { header1: "test" }); const getMessage = await messageModule.single("test_id"); expect(getMessage.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(getMessage.body).toMatchObject({ key1: "key1_value" }); expect(getMessage.statusCode).toBe(200); }); }); ================================================ FILE: src/__tests__/modules/Others.test.ts ================================================ import nock from "nock"; import { OthersModule } from "../../modules/Others.module"; describe("Others Module", () => { const othersModule = new OthersModule("test_key", "http://test.com"); it("getApiQuota", async () => { nock("http://test.com").get("/api-quota").reply(200, { quota: 1000, used: 42 }, { header1: "test" }); const result = await othersModule.getApiQuota(); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ quota: 1000, used: 42 }); expect(result.statusCode).toBe(200); }); }); ================================================ FILE: src/__tests__/modules/Recipient.test.ts ================================================ import nock from "nock"; import { RecipientModule } from "../../modules/email/Recipient.module"; import { BlockListRecipients, BlockListRecipientsPost, BlockListType } from "../../models"; describe("Recipient Module", () => { const recipientModule = new RecipientModule("test_key", "http://test.com"); it("list", async () => { const params = { limit: 20, page: 2, domain_id: "domain_id" }; nock("http://test.com").get("/recipients").query(params).reply(200, { key1: "key1_value" }, { header1: "test" }); const getRecipients = await recipientModule.list(params); expect(getRecipients.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(getRecipients.body).toMatchObject({ key1: "key1_value" }); expect(getRecipients.statusCode).toBe(200); }); it("single", async () => { nock("http://test.com").get("/recipients/test_id").reply(200, { key1: "key1_value" }, { header1: "test" }); const getRecipient = await recipientModule.single("test_id"); expect(getRecipient.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(getRecipient.body).toMatchObject({ key1: "key1_value" }); expect(getRecipient.statusCode).toBe(200); }); it("delete", async () => { nock("http://test.com").delete("/recipients/test_id").reply(200, { key1: "key1_value" }, { header1: "test" }); const deleteRecipient = await recipientModule.delete("test_id"); expect(deleteRecipient.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(deleteRecipient.body).toMatchObject({ key1: "key1_value" }); expect(deleteRecipient.statusCode).toBe(200); }); it("block list", async () => { const params = { limit: 20, page: 2, domain_id: "domain_id" }; nock("http://test.com") .get("/suppressions/blocklist") .query(params) .reply(200, { data: [{ id: "id_here" }] }, { header1: "blocklist-header" }); const blockList = await recipientModule.blockList(params); expect(blockList.headers).toMatchObject({ header1: "blocklist-header", "content-type": "application/json" }); expect(blockList.body).toMatchObject({ data: [{ id: "id_here" }] }); expect(blockList.statusCode).toBe(200); }); it("block recipients", async () => { const recipients: BlockListRecipients = { domain_id: "83gwk2j7zqz1nxyd", // not required recipients: ["test@example.com"], // If patterns is not defined, this property is required. patterns: [".*@example.com"], // If recipients is not defined, this property is required. }; nock("http://test.com") .post("/suppressions/blocklist", (body: any) => body.domain_id === "83gwk2j7zqz1nxyd" && body.recipients[0] === "test@example.com" && body.patterns[0] === ".*@example.com") .reply(200, { data: [{ id: "block_id" }] }, { header1: "block-header" }); const blockedRecipient = await recipientModule.blockRecipients(recipients); expect(blockedRecipient.headers).toMatchObject({ header1: "block-header", "content-type": "application/json" }); expect(blockedRecipient.body).toMatchObject({ data: [{ id: "block_id" }] }); expect(blockedRecipient.statusCode).toBe(200); }); it("delete block recipients by ids", async () => { nock("http://test.com").delete("/suppressions/blocklist", (body: any) => Array.isArray(body.ids) && body.ids[0] === "60f198790542d97fb66dfe52").reply(200, {}, { header1: "block-header" }); const ids = ["60f198790542d97fb66dfe52", "60f198790542d97fb66dfe53"]; const removed = await recipientModule.delBlockListRecipients(ids); expect(removed.headers).toMatchObject({ header1: "block-header", "content-type": "application/json" }); expect(removed.body).toMatchObject({}); expect(removed.statusCode).toBe(200); }); it("delete all block recipients", async () => { nock("http://test.com").delete("/suppressions/blocklist", (body: any) => body.all === true).reply(200, {}, { header1: "block-header" }); const removed = await recipientModule.delAllBlockListRecipients(); expect(removed.headers).toMatchObject({ header1: "block-header", "content-type": "application/json" }); expect(removed.body).toMatchObject({}); expect(removed.statusCode).toBe(200); }); it("hard bounce list", async () => { const params = { limit: 20, page: 2, domain_id: "domain_id" }; nock("http://test.com") .get("/suppressions/hard-bounces") .query(params) .reply(200, { data: [{ id: "id_here" }] }, { header1: "hard-bounces-header" }); const hardBouncedList = await recipientModule.blockList(params, BlockListType.HARD_BOUNCES_LIST); expect(hardBouncedList.headers).toMatchObject({ header1: "hard-bounces-header", "content-type": "application/json", }); expect(hardBouncedList.body).toMatchObject({ data: [{ id: "id_here" }] }); expect(hardBouncedList.statusCode).toBe(200); }); it("spam complaints list", async () => { const params = { limit: 20, page: 2, domain_id: "domain_id" }; nock("http://test.com") .get("/suppressions/spam-complaints") .query(params) .reply(200, { data: [{ id: "id_here" }] }, { header1: "spam-complaints-header" }); const spamComplaintsList = await recipientModule.blockList(params, BlockListType.SPAM_COMPLAINTS_LIST); expect(spamComplaintsList.headers).toMatchObject({ header1: "spam-complaints-header", "content-type": "application/json", }); expect(spamComplaintsList.body).toMatchObject({ data: [{ id: "id_here" }] }); expect(spamComplaintsList.statusCode).toBe(200); }); it("unsubscribes list", async () => { const params = { limit: 20, page: 2, domain_id: "domain_id" }; nock("http://test.com") .get("/suppressions/unsubscribes") .query(params) .reply(200, { data: [{ id: "id_here" }] }, { header1: "unsubscribes-header" }); const unsubscribesList = await recipientModule.blockList(params, BlockListType.UNSUBSCRIBES_LIST); expect(unsubscribesList.headers).toMatchObject({ header1: "unsubscribes-header", "content-type": "application/json", }); expect(unsubscribesList.body).toMatchObject({ data: [{ id: "id_here" }] }); expect(unsubscribesList.statusCode).toBe(200); }); it("on-hold-list", async () => { const params = { limit: 20, page: 2 }; nock("http://test.com") .get("/suppressions/on-hold-list") .query(params) .reply(200, { data: [{ id: "id_here" }] }, { header1: "on-hold-header" }); const onHoldList = await recipientModule.blockList(params, BlockListType.ON_HOLD_LIST); expect(onHoldList.headers).toMatchObject({ header1: "on-hold-header", "content-type": "application/json" }); expect(onHoldList.body).toMatchObject({ data: [{ id: "id_here" }] }); expect(onHoldList.statusCode).toBe(200); }); it("block hard bounces", async () => { const data: BlockListRecipientsPost = { domain_id: "test_domain_id", recipients: ["bounce@example.com"] }; nock("http://test.com") .post("/suppressions/hard-bounces", (body: any) => body.domain_id === "test_domain_id" && body.recipients[0] === "bounce@example.com") .reply(200, { data: [{ id: "block_id" }] }, { header1: "hard-bounces-header" }); const result = await recipientModule.blockRecipients(data, BlockListType.HARD_BOUNCES_LIST); expect(result.statusCode).toBe(200); }); it("block spam complaints", async () => { const data: BlockListRecipientsPost = { domain_id: "test_domain_id", recipients: ["spam@example.com"] }; nock("http://test.com") .post("/suppressions/spam-complaints", (body: any) => body.domain_id === "test_domain_id" && body.recipients[0] === "spam@example.com") .reply(200, { data: [{ id: "block_id" }] }, { header1: "spam-complaints-header" }); const result = await recipientModule.blockRecipients(data, BlockListType.SPAM_COMPLAINTS_LIST); expect(result.statusCode).toBe(200); }); it("block unsubscribes", async () => { const data: BlockListRecipientsPost = { domain_id: "test_domain_id", recipients: ["unsub@example.com"] }; nock("http://test.com") .post("/suppressions/unsubscribes", (body: any) => body.domain_id === "test_domain_id" && body.recipients[0] === "unsub@example.com") .reply(200, { data: [{ id: "block_id" }] }, { header1: "unsubscribes-header" }); const result = await recipientModule.blockRecipients(data, BlockListType.UNSUBSCRIBES_LIST); expect(result.statusCode).toBe(200); }); it("delete hard bounces by ids", async () => { const ids = ["hb_id_1", "hb_id_2"]; nock("http://test.com") .delete("/suppressions/hard-bounces", (body: any) => Array.isArray(body.ids) && body.ids[0] === "hb_id_1") .reply(204, {}, { header1: "hard-bounces-header" }); const result = await recipientModule.delBlockListRecipients(ids, BlockListType.HARD_BOUNCES_LIST); expect(result.statusCode).toBe(204); }); it("delete all hard bounces", async () => { nock("http://test.com") .delete("/suppressions/hard-bounces", (body: any) => body.all === true) .reply(204, {}, { header1: "hard-bounces-header" }); const result = await recipientModule.delAllBlockListRecipients(BlockListType.HARD_BOUNCES_LIST); expect(result.statusCode).toBe(204); }); it("delete spam complaints by ids", async () => { const ids = ["sc_id_1", "sc_id_2"]; nock("http://test.com") .delete("/suppressions/spam-complaints", (body: any) => Array.isArray(body.ids) && body.ids[0] === "sc_id_1") .reply(204, {}, { header1: "spam-complaints-header" }); const result = await recipientModule.delBlockListRecipients(ids, BlockListType.SPAM_COMPLAINTS_LIST); expect(result.statusCode).toBe(204); }); it("delete all spam complaints", async () => { nock("http://test.com") .delete("/suppressions/spam-complaints", (body: any) => body.all === true) .reply(204, {}, { header1: "spam-complaints-header" }); const result = await recipientModule.delAllBlockListRecipients(BlockListType.SPAM_COMPLAINTS_LIST); expect(result.statusCode).toBe(204); }); it("delete unsubscribes by ids", async () => { const ids = ["unsub_id_1", "unsub_id_2"]; nock("http://test.com") .delete("/suppressions/unsubscribes", (body: any) => Array.isArray(body.ids) && body.ids[0] === "unsub_id_1") .reply(204, {}, { header1: "unsubscribes-header" }); const result = await recipientModule.delBlockListRecipients(ids, BlockListType.UNSUBSCRIBES_LIST); expect(result.statusCode).toBe(204); }); it("delete all unsubscribes", async () => { nock("http://test.com") .delete("/suppressions/unsubscribes", (body: any) => body.all === true) .reply(204, {}, { header1: "unsubscribes-header" }); const result = await recipientModule.delAllBlockListRecipients(BlockListType.UNSUBSCRIBES_LIST); expect(result.statusCode).toBe(204); }); it("delete on-hold-list by ids", async () => { const ids = ["oh_id_1", "oh_id_2"]; nock("http://test.com") .delete("/suppressions/on-hold-list", (body: any) => Array.isArray(body.ids) && body.ids[0] === "oh_id_1") .reply(204, {}, { header1: "on-hold-header" }); const result = await recipientModule.delBlockListRecipients(ids, BlockListType.ON_HOLD_LIST); expect(result.statusCode).toBe(204); }); it("delete all on-hold-list", async () => { nock("http://test.com") .delete("/suppressions/on-hold-list", (body: any) => body.all === true) .reply(204, {}, { header1: "on-hold-header" }); const result = await recipientModule.delAllBlockListRecipients(BlockListType.ON_HOLD_LIST); expect(result.statusCode).toBe(204); }); describe("limit validation", () => { test.each([ ["blocklist limit below minimum", 9], ["blocklist limit above maximum", 101], ])("%s", async (_label, limit) => { await expect(recipientModule.blockList({ limit }, BlockListType.BLOCK_LIST)).rejects.toThrow("Limit must be between 10 and 100."); }); test.each([ ["hard-bounces limit below minimum", 9], ["hard-bounces limit above maximum", 101], ])("%s", async (_label, limit) => { await expect(recipientModule.blockList({ limit }, BlockListType.HARD_BOUNCES_LIST)).rejects.toThrow("Limit must be between 10 and 100."); }); test.each([ ["spam-complaints limit below minimum", 9], ["spam-complaints limit above maximum", 101], ])("%s", async (_label, limit) => { await expect(recipientModule.blockList({ limit }, BlockListType.SPAM_COMPLAINTS_LIST)).rejects.toThrow("Limit must be between 10 and 100."); }); test.each([ ["unsubscribes limit below minimum", 9], ["unsubscribes limit above maximum", 101], ])("%s", async (_label, limit) => { await expect(recipientModule.blockList({ limit }, BlockListType.UNSUBSCRIBES_LIST)).rejects.toThrow("Limit must be between 10 and 100."); }); test.each([ ["on-hold-list limit below minimum", 9], ["on-hold-list limit above maximum", 101], ])("%s", async (_label, limit) => { await expect(recipientModule.blockList({ limit }, BlockListType.ON_HOLD_LIST)).rejects.toThrow("Limit must be between 10 and 100."); }); }); describe("blockRecipients blocklist — mutual requirement", () => { it("throws when neither recipients nor patterns are provided", async () => { await expect(recipientModule.blockRecipients({})).rejects.toThrow("Either recipients or patterns must be provided."); }); it("throws when recipients is empty and patterns is absent", async () => { await expect(recipientModule.blockRecipients({ recipients: [] })).rejects.toThrow("Either recipients or patterns must be provided."); }); it("throws when patterns is empty and recipients is absent", async () => { await expect(recipientModule.blockRecipients({ patterns: [] })).rejects.toThrow("Either recipients or patterns must be provided."); }); it("succeeds with only recipients", async () => { nock("http://test.com") .post("/suppressions/blocklist", (body: any) => Array.isArray(body.recipients) && body.recipients[0] === "only@example.com") .reply(200, { data: [] }, {}); const result = await recipientModule.blockRecipients({ recipients: ["only@example.com"] }); expect(result.statusCode).toBe(200); }); it("succeeds with only patterns", async () => { nock("http://test.com") .post("/suppressions/blocklist", (body: any) => Array.isArray(body.patterns) && body.patterns[0] === ".*@example.com") .reply(200, { data: [] }, {}); const result = await recipientModule.blockRecipients({ patterns: [".*@example.com"] }); expect(result.statusCode).toBe(200); }); }); describe("blockRecipients — empty recipients validation", () => { test.each([ ["hard-bounces", BlockListType.HARD_BOUNCES_LIST], ["spam-complaints", BlockListType.SPAM_COMPLAINTS_LIST], ["unsubscribes", BlockListType.UNSUBSCRIBES_LIST], ])("throws when recipients is empty for %s", async (_label, type) => { await expect( recipientModule.blockRecipients({ domain_id: "test_domain_id", recipients: [] }, type as BlockListType.HARD_BOUNCES_LIST | BlockListType.SPAM_COMPLAINTS_LIST | BlockListType.UNSUBSCRIBES_LIST) ).rejects.toThrow("Recipients must not be empty."); }); }); }); ================================================ FILE: src/__tests__/modules/SMS.test.ts ================================================ import { SMSModule } from "../../modules/SMS.module"; import { SMSPersonalization, SMSParams } from "../../models"; import nock from "nock"; import { SmsActivityModule } from "../../modules/sms/Activity.module"; import { SmsNumberModule } from "../../modules/sms/Number.module"; import { SmsInboundModule } from "../../modules/sms/Inbound.module"; import { SmsMessageModule } from "../../modules/sms/Message.module"; import { SmsRecipientModule } from "../../modules/sms/Recipient.module"; import { SmsWebhookModule } from "../../modules/sms/Webhook.module"; describe("SMS Module", () => { const smsModule = new SMSModule("test_key", "http://test.com"); it("Constructor", () => { expect(smsModule.activity instanceof SmsActivityModule).toBe(true); expect(smsModule.number instanceof SmsNumberModule).toBe(true); expect(smsModule.inbound instanceof SmsInboundModule).toBe(true); expect(smsModule.message instanceof SmsMessageModule).toBe(true); expect(smsModule.recipient instanceof SmsRecipientModule).toBe(true); expect(smsModule.webhook instanceof SmsWebhookModule).toBe(true); }); it("send", async () => { nock("http://test.com").post("/sms").reply(202, { key1: "key1_value" }, { "x-sms-message-id": "test" }); const personalization: SMSPersonalization[] = []; personalization.push(new SMSPersonalization("+19191234567", { name: "Dummy" })); personalization.push(new SMSPersonalization("+19199876543", { name: "Not Dummy" })); const params = new SMSParams() .setFrom("+19191234567") .setTo(["+19191234567", "+19199876543"]) .setText("Hey {{name}}! This is just a friendly hello :D") .setPersonalization(personalization); const sendEmail = await smsModule.send(params); expect(sendEmail.headers).toMatchObject({ "x-sms-message-id": "test", "content-type": "application/json" }); expect(sendEmail.body).toMatchObject({ key1: "key1_value" }); expect(sendEmail.statusCode).toBe(202); }); }); ================================================ FILE: src/__tests__/modules/Schedule.test.ts ================================================ import nock from "nock"; import { ScheduleModule } from "../../modules/email/Schedule.module"; describe("Schedule Module", () => { const scheduleModule = new ScheduleModule("test_key", "http://test.com"); it("list", async () => { const params = { domain_id: "domain_id", status: "scheduled" as const, page: 1, limit: 10 }; nock("http://test.com").get("/message-schedules").query(params).reply(200, { key1: "schedule_list" }, { header1: "test" }); const result = await scheduleModule.list(params); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "schedule_list" }); expect(result.statusCode).toBe(200); }); it("single", async () => { nock("http://test.com").get("/message-schedules/test_message_id").reply(200, { key1: "schedule_value" }, { header1: "test" }); const result = await scheduleModule.single("test_message_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "schedule_value" }); expect(result.statusCode).toBe(200); }); it("delete", async () => { nock("http://test.com").delete("/message-schedules/test_message_id").reply(204); const result = await scheduleModule.delete("test_message_id"); expect(result.statusCode).toBe(204); }); }); ================================================ FILE: src/__tests__/modules/SmsActivity.test.ts ================================================ import nock from "nock"; import { SmsActivityModule } from "../../modules/sms/Activity.module"; describe("SMS Activity Module", () => { const smsActivityModule = new SmsActivityModule("test_key", "http://test.com"); it("list", async () => { const params = { sms_number_id: "sms_number_id", page: 1, limit: 10 }; nock("http://test.com").get("/sms-activity").query(params).reply(200, { key1: "sms_activity_list" }, { header1: "test" }); const result = await smsActivityModule.list(params); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "sms_activity_list" }); expect(result.statusCode).toBe(200); }); }); ================================================ FILE: src/__tests__/modules/SmsInbound.test.ts ================================================ import nock from "nock"; import { SmsInboundModule } from "../../modules/sms/Inbound.module"; import { SmsInbound } from "../../models"; describe("SMS Inbound Module", () => { const smsInboundModule = new SmsInboundModule("test_key", "http://test.com"); const smsInbound = new SmsInbound("Test Inbound", "sms_number_id", "https://example.com/forward", true); it("create", async () => { nock("http://test.com").post("/sms-inbounds").reply(201, { key1: "sms_inbound_created" }, { header1: "test" }); const result = await smsInboundModule.create(smsInbound); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "sms_inbound_created" }); expect(result.statusCode).toBe(201); }); it("list", async () => { const params = { sms_number_id: "sms_number_id", page: 1, limit: 10 }; nock("http://test.com").get("/sms-inbounds").query(params).reply(200, { key1: "sms_inbound_list" }, { header1: "test" }); const result = await smsInboundModule.list(params); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "sms_inbound_list" }); expect(result.statusCode).toBe(200); }); it("single", async () => { nock("http://test.com").get("/sms-inbounds/test_sms_inbound_id").reply(200, { key1: "sms_inbound_value" }, { header1: "test" }); const result = await smsInboundModule.single("test_sms_inbound_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "sms_inbound_value" }); expect(result.statusCode).toBe(200); }); it("update", async () => { nock("http://test.com").put("/sms-inbounds/test_sms_inbound_id").reply(200, { key1: "sms_inbound_updated" }, { header1: "test" }); const result = await smsInboundModule.update("test_sms_inbound_id", { name: "Updated Inbound", enabled: false }); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "sms_inbound_updated" }); expect(result.statusCode).toBe(200); }); it("delete", async () => { nock("http://test.com").delete("/sms-inbounds/test_sms_inbound_id").reply(200, { key1: "sms_inbound_deleted" }, { header1: "test" }); const result = await smsInboundModule.delete("test_sms_inbound_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "sms_inbound_deleted" }); expect(result.statusCode).toBe(200); }); }); ================================================ FILE: src/__tests__/modules/SmsMessage.test.ts ================================================ import nock from "nock"; import { SmsMessageModule } from "../../modules/sms/Message.module"; describe("SMS Message Module", () => { const smsMessageModule = new SmsMessageModule("test_key", "http://test.com"); it("list", async () => { const params = { page: 1, limit: 10 }; nock("http://test.com").get("/sms-messages").query(params).reply(200, { key1: "sms_message_list" }, { header1: "test" }); const result = await smsMessageModule.list(params); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "sms_message_list" }); expect(result.statusCode).toBe(200); }); it("single", async () => { nock("http://test.com").get("/sms-messages/test_sms_message_id").reply(200, { key1: "sms_message_value" }, { header1: "test" }); const result = await smsMessageModule.single("test_sms_message_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "sms_message_value" }); expect(result.statusCode).toBe(200); }); }); ================================================ FILE: src/__tests__/modules/SmsNumber.test.ts ================================================ import nock from "nock"; import { SmsNumberModule } from "../../modules/sms/Number.module"; describe("SMS Number Module", () => { const smsNumberModule = new SmsNumberModule("test_key", "http://test.com"); it("list", async () => { const params = { page: 1, limit: 10 }; nock("http://test.com").get("/sms-numbers").query(params).reply(200, { key1: "sms_number_list" }, { header1: "test" }); const result = await smsNumberModule.list(params); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "sms_number_list" }); expect(result.statusCode).toBe(200); }); it("single", async () => { nock("http://test.com").get("/sms-numbers/test_sms_number_id").reply(200, { key1: "sms_number_value" }, { header1: "test" }); const result = await smsNumberModule.single("test_sms_number_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "sms_number_value" }); expect(result.statusCode).toBe(200); }); it("update", async () => { nock("http://test.com").put("/sms-numbers/test_sms_number_id").reply(200, { key1: "sms_number_updated" }, { header1: "test" }); const result = await smsNumberModule.update("test_sms_number_id", true); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "sms_number_updated" }); expect(result.statusCode).toBe(200); }); it("delete", async () => { nock("http://test.com").delete("/sms-numbers/test_sms_number_id").reply(200, { key1: "sms_number_deleted" }, { header1: "test" }); const result = await smsNumberModule.delete("test_sms_number_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "sms_number_deleted" }); expect(result.statusCode).toBe(200); }); }); ================================================ FILE: src/__tests__/modules/SmsRecipient.test.ts ================================================ import nock from "nock"; import { SmsRecipientModule } from "../../modules/sms/Recipient.module"; describe("SMS Recipient Module", () => { const smsRecipientModule = new SmsRecipientModule("test_key", "http://test.com"); it("list", async () => { const params = { sms_number_id: "sms_number_id", status: "active" as const, page: 1, limit: 10 }; nock("http://test.com").get("/sms-recipients").query(params).reply(200, { key1: "sms_recipient_list" }, { header1: "test" }); const result = await smsRecipientModule.list(params); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "sms_recipient_list" }); expect(result.statusCode).toBe(200); }); it("single", async () => { nock("http://test.com").get("/sms-recipients/test_sms_recipient_id").reply(200, { key1: "sms_recipient_value" }, { header1: "test" }); const result = await smsRecipientModule.single("test_sms_recipient_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "sms_recipient_value" }); expect(result.statusCode).toBe(200); }); it("update - opt_out", async () => { nock("http://test.com").put("/sms-recipients/test_sms_recipient_id").reply(200, { key1: "sms_recipient_updated" }, { header1: "test" }); const result = await smsRecipientModule.update("test_sms_recipient_id", "opt_out"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "sms_recipient_updated" }); expect(result.statusCode).toBe(200); }); it("update - active", async () => { nock("http://test.com").put("/sms-recipients/test_sms_recipient_id").reply(200, { key1: "sms_recipient_activated" }, { header1: "test" }); const result = await smsRecipientModule.update("test_sms_recipient_id", "active"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "sms_recipient_activated" }); expect(result.statusCode).toBe(200); }); }); ================================================ FILE: src/__tests__/modules/SmsWebhook.test.ts ================================================ import nock from "nock"; import { SmsWebhookModule } from "../../modules/sms/Webhook.module"; import { SmsWebhook, SmsWebhookEventType } from "../../models"; describe("SMS Webhook Module", () => { const smsWebhookModule = new SmsWebhookModule("test_key", "http://test.com"); const smsWebhook = new SmsWebhook( "Test SMS Webhook", "https://example.com/sms-webhook", [SmsWebhookEventType.SENT, SmsWebhookEventType.DELIVERED], "sms_number_id", true, ); it("create", async () => { nock("http://test.com").post("/sms-webhooks").reply(201, { key1: "sms_webhook_created" }, { header1: "test" }); const result = await smsWebhookModule.create(smsWebhook); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "sms_webhook_created" }); expect(result.statusCode).toBe(201); }); it("list", async () => { nock("http://test.com") .get("/sms-webhooks") .query({ sms_number_id: "sms_number_id" }) .reply(200, { key1: "sms_webhook_list" }, { header1: "test" }); const result = await smsWebhookModule.list({ sms_number_id: "sms_number_id" }); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "sms_webhook_list" }); expect(result.statusCode).toBe(200); }); it("single", async () => { nock("http://test.com").get("/sms-webhooks/test_sms_webhook_id").reply(200, { key1: "sms_webhook_value" }, { header1: "test" }); const result = await smsWebhookModule.single("test_sms_webhook_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "sms_webhook_value" }); expect(result.statusCode).toBe(200); }); it("update", async () => { nock("http://test.com").put("/sms-webhooks/test_sms_webhook_id").reply(200, { key1: "sms_webhook_updated" }, { header1: "test" }); const result = await smsWebhookModule.update("test_sms_webhook_id", { name: "Updated Webhook", enabled: false }); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "sms_webhook_updated" }); expect(result.statusCode).toBe(200); }); it("delete", async () => { nock("http://test.com").delete("/sms-webhooks/test_sms_webhook_id").reply(200, { key1: "sms_webhook_deleted" }, { header1: "test" }); const result = await smsWebhookModule.delete("test_sms_webhook_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "sms_webhook_deleted" }); expect(result.statusCode).toBe(200); }); }); ================================================ FILE: src/__tests__/modules/SmtpUser.test.ts ================================================ import nock from "nock"; import { SmtpUserModule } from "../../modules/email/SmtpUser.module"; describe("SmtpUser Module", () => { const smtpUserModule = new SmtpUserModule("test_key", "http://test.com"); it("list", async () => { const params = { page: 1, limit: 10 }; nock("http://test.com").get("/domains/test_id/smtp-users").query(params).reply(200, { key1: "smtp_list" }, { header1: "test" }); const result = await smtpUserModule.list("test_id", params); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "smtp_list" }); expect(result.statusCode).toBe(200); }); it("single", async () => { nock("http://test.com").get("/domains/test_id/smtp-users/smtp_user_id").reply(200, { key1: "smtp_user" }, { header1: "test" }); const result = await smtpUserModule.single("test_id", "smtp_user_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "smtp_user" }); expect(result.statusCode).toBe(200); }); it("create", async () => { nock("http://test.com") .post("/domains/test_id/smtp-users", { name: "smtp_user_name" }) .reply(201, { key1: "smtp_created" }, { header1: "test" }); const result = await smtpUserModule.create("test_id", { name: "smtp_user_name" }); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "smtp_created" }); expect(result.statusCode).toBe(201); }); it("create with enabled field", async () => { nock("http://test.com") .post("/domains/test_id/smtp-users", { name: "smtp_user_name", enabled: true }) .reply(201, { key1: "smtp_created" }, { header1: "test" }); const result = await smtpUserModule.create("test_id", { name: "smtp_user_name", enabled: true }); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "smtp_created" }); expect(result.statusCode).toBe(201); }); it("update", async () => { nock("http://test.com").put("/domains/test_id/smtp-users/smtp_user_id").reply(200, { key1: "smtp_updated" }, { header1: "test" }); const result = await smtpUserModule.update("test_id", "smtp_user_id", { name: "new_name" }); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "smtp_updated" }); expect(result.statusCode).toBe(200); }); it("update with enabled field", async () => { nock("http://test.com") .put("/domains/test_id/smtp-users/smtp_user_id", { name: "new_name", enabled: false }) .reply(200, { key1: "smtp_updated" }, { header1: "test" }); const result = await smtpUserModule.update("test_id", "smtp_user_id", { name: "new_name", enabled: false }); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "smtp_updated" }); expect(result.statusCode).toBe(200); }); it("delete", async () => { nock("http://test.com").delete("/domains/test_id/smtp-users/smtp_user_id").reply(204); const result = await smtpUserModule.delete("test_id", "smtp_user_id"); expect(result.statusCode).toBe(204); }); }); ================================================ FILE: src/__tests__/modules/Template.test.ts ================================================ import nock from "nock"; import { TemplateModule } from "../../modules/email/Template.module"; describe("Template Module", () => { const templateModule = new TemplateModule("test_key", "http://test.com"); const templateParams = { name: "Test Template", text: "Hello {{name}}", html: "

Hello {{name}}

" }; it("list", async () => { const params = { domain_id: "domain_id", page: 1, limit: 10 }; nock("http://test.com").get("/templates").query(params).reply(200, { key1: "template_list" }, { header1: "test" }); const result = await templateModule.list(params); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "template_list" }); expect(result.statusCode).toBe(200); }); it("list with no arguments", async () => { nock("http://test.com").get("/templates").reply(200, { key1: "template_list_all" }, { header1: "test" }); const result = await templateModule.list(); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "template_list_all" }); expect(result.statusCode).toBe(200); }); it("single", async () => { nock("http://test.com").get("/templates/test_template_id").reply(200, { key1: "template_value" }, { header1: "test" }); const result = await templateModule.single("test_template_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "template_value" }); expect(result.statusCode).toBe(200); }); it("create", async () => { nock("http://test.com") .post("/templates", { name: "Test Template", text: "Hello {{name}}", html: "

Hello {{name}}

" }) .reply(201, { key1: "template_created" }, { header1: "test" }); const result = await templateModule.create(templateParams); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "template_created" }); expect(result.statusCode).toBe(201); }); it("create with optional fields", async () => { const params = { name: "Test Template", text: "Hello {{name}}", html: "

Hello {{name}}

", categories: ["cat1", "cat2"], domain_id: "domain_id", tags: ["tag1", "tag2"], auto_generate: true, }; nock("http://test.com") .post("/templates", { name: "Test Template", text: "Hello {{name}}", html: "

Hello {{name}}

", categories: ["cat1", "cat2"], domain_id: "domain_id", tags: ["tag1", "tag2"], auto_generate: true, }) .reply(201, { key1: "template_created" }, { header1: "test" }); const result = await templateModule.create(params); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "template_created" }); expect(result.statusCode).toBe(201); }); it("update", async () => { nock("http://test.com") .put("/templates/test_template_id", { name: "Updated Template" }) .reply(200, { key1: "template_updated" }, { header1: "test" }); const result = await templateModule.update("test_template_id", { name: "Updated Template" }); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "template_updated" }); expect(result.statusCode).toBe(200); }); it("update with optional fields", async () => { const params = { name: "Updated Template", categories: ["cat1"], domain_id: "domain_id", tags: ["tag1"], text: "Hello {{name}}", html: "

Hello {{name}}

", auto_generate: false, }; nock("http://test.com") .put("/templates/test_template_id", { name: "Updated Template", categories: ["cat1"], domain_id: "domain_id", tags: ["tag1"], text: "Hello {{name}}", html: "

Hello {{name}}

", auto_generate: false, }) .reply(200, { key1: "template_updated" }, { header1: "test" }); const result = await templateModule.update("test_template_id", params); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "template_updated" }); expect(result.statusCode).toBe(200); }); it("delete", async () => { nock("http://test.com").delete("/templates/test_template_id").reply(200, { key1: "template_deleted" }, { header1: "test" }); const result = await templateModule.delete("test_template_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "template_deleted" }); expect(result.statusCode).toBe(200); }); }); ================================================ FILE: src/__tests__/modules/Token.test.ts ================================================ import nock from "nock"; import { TokenModule } from "../../modules/Token.module"; import { Token, TokenScopeType } from "../../models"; describe("Token Module", () => { const token = new Token("token1", [TokenScopeType.EMAIL_FULL, TokenScopeType.ANALYTICS_FULL], "domain_id_test"); const tokenModule = new TokenModule("test_key", "http://test.com"); it("list", async () => { const params = { page: 1, limit: 10 }; nock("http://test.com").get("/token").query(params).reply(200, { key1: "key1_value" }, { header1: "test" }); const result = await tokenModule.list(params); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "key1_value" }); expect(result.statusCode).toBe(200); }); it("list without params", async () => { nock("http://test.com").get("/token").reply(200, { key1: "key1_value" }, { header1: "test" }); const result = await tokenModule.list(); expect(result.statusCode).toBe(200); }); it("single", async () => { nock("http://test.com").get("/token/test_id").reply(200, { key1: "key1_value" }, { header1: "test" }); const result = await tokenModule.single("test_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "key1_value" }); expect(result.statusCode).toBe(200); }); it("create", async () => { nock("http://test.com").post("/token", (body: any) => body.name === "token1" && Array.isArray(body.scopes) && body.scopes[0] === "email_full" && body.domain_id === "domain_id_test").reply(200, { key1: "token1_value" }, { header1: "test" }); const createToken = await tokenModule.create(token); expect(createToken.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(createToken.body).toMatchObject({ key1: "token1_value" }); expect(createToken.statusCode).toBe(200); }); it("update", async () => { nock("http://test.com").put("/token/test_id", (body: any) => body.name === "updated_token").reply(200, { key1: "key1_value" }, { header1: "test" }); const result = await tokenModule.update("test_id", { name: "updated_token" }); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "key1_value" }); expect(result.statusCode).toBe(200); }); it("update with status", async () => { nock("http://test.com") .put("/token/test_id", (body: any) => body.status === "pause") .reply(200, { key1: "key1_value" }, { header1: "test" }); const result = await tokenModule.update("test_id", { status: "pause" }); expect(result.statusCode).toBe(200); }); it("settings", async () => { nock("http://test.com").put("/token/test_id", (body: any) => body.status === "pause").reply(200, { key1: "key1_value" }, { header1: "test" }); const updateSettings = await tokenModule.updateSettings("test_id", { status: "pause" }); expect(updateSettings.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(updateSettings.body).toMatchObject({ key1: "key1_value" }); expect(updateSettings.statusCode).toBe(200); }); it("settings with name", async () => { nock("http://test.com") .put("/token/test_id", (body: any) => body.name === "renamed_token") .reply(200, { key1: "key1_value" }, { header1: "test" }); const result = await tokenModule.updateSettings("test_id", { name: "renamed_token" }); expect(result.statusCode).toBe(200); }); it("delete", async () => { nock("http://test.com").delete("/token/test_id").reply(200, { key1: "key1_value" }, { header1: "test" }); const deleteDomain = await tokenModule.delete("test_id"); expect(deleteDomain.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(deleteDomain.body).toMatchObject({ key1: "key1_value" }); expect(deleteDomain.statusCode).toBe(200); }); }); ================================================ FILE: src/__tests__/modules/User.test.ts ================================================ import nock from "nock"; import { UserModule } from "../../modules/User.module"; import { UserRole, UserPermission } from "../../models"; describe("User Module", () => { const userModule = new UserModule("test_key", "http://test.com"); it("list", async () => { const params = { page: 1, limit: 10 }; nock("http://test.com").get("/users").query(params).reply(200, { key1: "user_list" }, { header1: "test" }); const result = await userModule.list(params); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "user_list" }); expect(result.statusCode).toBe(200); }); it("single", async () => { nock("http://test.com").get("/users/test_user_id").reply(200, { key1: "user_value" }, { header1: "test" }); const result = await userModule.single("test_user_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "user_value" }); expect(result.statusCode).toBe(200); }); it("create", async () => { const data = { email: "user@example.com", role: "admin" }; nock("http://test.com").post("/users", (body: any) => body.email === "user@example.com" && body.role === "admin").reply(201, { key1: "user_created" }, { header1: "test" }); const result = await userModule.create(data); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "user_created" }); expect(result.statusCode).toBe(201); }); it("create with all fields", async () => { nock("http://test.com") .post("/users", (body: any) => body.email === "user@example.com" && body.role === "Custom User" && Array.isArray(body.permissions) && body.permissions[0] === "read-activity" && Array.isArray(body.templates) && Array.isArray(body.domains) && body.requires_periodic_password_change === true ) .reply(201, { key1: "user_created" }, { header1: "test" }); const result = await userModule.create({ email: "user@example.com", role: UserRole.CustomUser, permissions: [UserPermission.ReadActivity, UserPermission.ReadEmail], templates: ["tmpl_123"], domains: ["domain_123"], requires_periodic_password_change: true, }); expect(result.statusCode).toBe(201); }); it("update", async () => { const data = { role: "manager" }; nock("http://test.com").put("/users/test_user_id", (body: any) => body.role === "manager").reply(200, { key1: "user_updated" }, { header1: "test" }); const result = await userModule.update("test_user_id", data); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "user_updated" }); expect(result.statusCode).toBe(200); }); it("update with permissions and domains", async () => { nock("http://test.com") .put("/users/test_user_id", (body: any) => body.role === "Custom User" && Array.isArray(body.permissions) && Array.isArray(body.domains) && body.requires_periodic_password_change === false ) .reply(200, { key1: "user_updated" }, { header1: "test" }); const result = await userModule.update("test_user_id", { role: UserRole.CustomUser, permissions: [UserPermission.ManageDomain], domains: ["domain_123"], requires_periodic_password_change: false, }); expect(result.statusCode).toBe(200); }); it("delete", async () => { nock("http://test.com").delete("/users/test_user_id").reply(204, {}, { header1: "test" }); const result = await userModule.delete("test_user_id"); expect(result.statusCode).toBe(204); }); it("listInvites", async () => { const params = { page: 1, limit: 10 }; nock("http://test.com").get("/invites").query(params).reply(200, { key1: "invite_list" }, { header1: "test" }); const result = await userModule.listInvites(params); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "invite_list" }); expect(result.statusCode).toBe(200); }); it("singleInvite", async () => { nock("http://test.com").get("/invites/test_invite_id").reply(200, { key1: "invite_value" }, { header1: "test" }); const result = await userModule.singleInvite("test_invite_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "invite_value" }); expect(result.statusCode).toBe(200); }); it("resendInvite", async () => { nock("http://test.com").post("/invites/test_invite_id/resend").reply(200, { key1: "invite_resent" }, { header1: "test" }); const result = await userModule.resendInvite("test_invite_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "invite_resent" }); expect(result.statusCode).toBe(200); }); it("deleteInvite", async () => { nock("http://test.com").delete("/invites/test_invite_id").reply(204, {}, { header1: "test" }); const result = await userModule.deleteInvite("test_invite_id"); expect(result.statusCode).toBe(204); }); }); ================================================ FILE: src/__tests__/modules/Webhook.test.ts ================================================ import nock from "nock"; import { EmailWebhookModule } from "../../modules/email/Webhook.module"; import { EmailWebhook, EmailWebhookEventType } from "../../models"; describe("Email Webhook Module", () => { const webhookModule = new EmailWebhookModule("test_key", "http://test.com"); const webhook = new EmailWebhook({ url: "https://example.com/webhook", name: "Test Webhook", events: [EmailWebhookEventType.SENT, EmailWebhookEventType.DELIVERED], domain_id: "test_domain_id", }); it("create sends POST to /webhooks with required fields", async () => { nock("http://test.com") .post("/webhooks", { url: "https://example.com/webhook", name: "Test Webhook", events: [EmailWebhookEventType.SENT, EmailWebhookEventType.DELIVERED], domain_id: "test_domain_id", }) .reply(201, { key1: "webhook_created" }, { header1: "test" }); const result = await webhookModule.create(webhook); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "webhook_created" }); expect(result.statusCode).toBe(201); }); it("create with enabled field", async () => { const webhookWithEnabled = new EmailWebhook({ url: "https://example.com/webhook", name: "Test Webhook", events: [EmailWebhookEventType.SENT], domain_id: "test_domain_id", enabled: false, }); nock("http://test.com") .post("/webhooks", (body) => body.enabled === false) .reply(201, { key1: "webhook_created" }, {}); const result = await webhookModule.create(webhookWithEnabled); expect(result.statusCode).toBe(201); }); it("create with version field", async () => { const webhookWithVersion = new EmailWebhook({ url: "https://example.com/webhook", name: "Test Webhook", events: [EmailWebhookEventType.SENT], domain_id: "test_domain_id", version: 2, }); nock("http://test.com") .post("/webhooks", (body) => body.version === 2) .reply(201, { key1: "webhook_created" }, {}); const result = await webhookModule.create(webhookWithVersion); expect(result.statusCode).toBe(201); }); it("create with editable field", async () => { const webhookWithEditable = new EmailWebhook({ url: "https://example.com/webhook", name: "Test Webhook", events: [EmailWebhookEventType.SENT], domain_id: "test_domain_id", editable: true, }); nock("http://test.com") .post("/webhooks", (body) => body.editable === true) .reply(201, { key1: "webhook_created" }, {}); const result = await webhookModule.create(webhookWithEditable); expect(result.statusCode).toBe(201); }); it("list sends GET to /webhooks with domain_id and limit", async () => { nock("http://test.com") .get("/webhooks") .query({ domain_id: "test_domain_id", limit: 10 }) .reply(200, { key1: "webhook_list" }, { header1: "test" }); const result = await webhookModule.list("test_domain_id", { limit: 10 }); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "webhook_list" }); expect(result.statusCode).toBe(200); }); it("list sends GET to /webhooks with page query param", async () => { nock("http://test.com") .get("/webhooks") .query({ domain_id: "test_domain_id", page: 2 }) .reply(200, { key1: "webhook_list" }, {}); const result = await webhookModule.list("test_domain_id", { page: 2 }); expect(result.statusCode).toBe(200); }); it("single", async () => { nock("http://test.com").get("/webhooks/test_webhook_id").reply(200, { key1: "webhook_value" }, { header1: "test" }); const result = await webhookModule.single("test_webhook_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "webhook_value" }); expect(result.statusCode).toBe(200); }); it("update sends PUT to /webhooks/{id} with body fields", async () => { nock("http://test.com") .put("/webhooks/test_webhook_id", { name: "Updated Webhook", enabled: false }) .reply(200, { key1: "webhook_updated" }, { header1: "test" }); const result = await webhookModule.update("test_webhook_id", { name: "Updated Webhook", enabled: false }); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "webhook_updated" }); expect(result.statusCode).toBe(200); }); it("update with url field", async () => { nock("http://test.com") .put("/webhooks/test_webhook_id", (body) => body.url === "https://example.com/new-hook") .reply(200, { key1: "webhook_updated" }, {}); const result = await webhookModule.update("test_webhook_id", { url: "https://example.com/new-hook" }); expect(result.statusCode).toBe(200); }); it("update with events field", async () => { nock("http://test.com") .put("/webhooks/test_webhook_id", (body) => Array.isArray(body.events) && body.events.includes(EmailWebhookEventType.CLICKED)) .reply(200, { key1: "webhook_updated" }, {}); const result = await webhookModule.update("test_webhook_id", { events: [EmailWebhookEventType.CLICKED] }); expect(result.statusCode).toBe(200); }); it("update with version field", async () => { nock("http://test.com") .put("/webhooks/test_webhook_id", (body) => body.version === 2) .reply(200, { key1: "webhook_updated" }, {}); const result = await webhookModule.update("test_webhook_id", { version: 2 }); expect(result.statusCode).toBe(200); }); it("delete", async () => { nock("http://test.com").delete("/webhooks/test_webhook_id").reply(200, { key1: "webhook_deleted" }, { header1: "test" }); const result = await webhookModule.delete("test_webhook_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "webhook_deleted" }); expect(result.statusCode).toBe(200); }); }); ================================================ FILE: src/__tests__/services/mailersend.utils.test.ts ================================================ import { MailerSendUtils } from "../../services/mailersend.utils"; describe("utils", () => { it("webhook check", async () => { const body = Buffer.from( '{"type":"activity.sent","domain_id":"test_domain","created_at":"2022-09-08T20:06:12.062074Z","webhook_id":"webhook_test","url":"https:\\/\\/webhook.site\\/test","data":{"object":"activity","id":"631a6250bd4f6bd6844a2307","type":"sent","created_at":"2022-09-08T20:06:12.051000Z","email":{"object":"email","id":"631a6250bd4f6bd6844a2307","created_at":"2022-09-08T20:06:11.887000Z","from":"donotreply@mailsender.com","subject":"Test Message","status":"sent","tags":null,"message":{"object":"message","id":"631a6250bd4f6bd6844a2307","created_at":"2022-09-08T20:06:11.399000Z"},"recipient":{"object":"recipient","id":"631a6250bd4f6bd6844a2307","email":"test@test.com","created_at":"2022-03-31T21:31:37.304000Z"}},"morph":null,"template_id":""}}', ); const secret = "yXdTVu1YewsKiuN2bcILlFHsljmR9kaU"; const signature = "445e75aab3d8ea9169d134189a2814f06858977bd9cdc69324264e39f47bda2e"; const isLegit = MailerSendUtils.verifyWebHook(body, signature, secret); expect(isLegit).toBeTruthy(); }); it("no body", async () => { try { MailerSendUtils.verifyWebHook(undefined as any, "test", "test"); } catch (e: any) { expect(e?.message).toBe("No raw body provided"); } }); it("no signature", async () => { try { MailerSendUtils.verifyWebHook(Buffer.from("test"), undefined as any, "test"); } catch (e: any) { expect(e?.message).toBe("No signature provided"); } }); it("no secret", async () => { try { MailerSendUtils.verifyWebHook(Buffer.from("test"), "test", undefined as any); } catch (e: any) { expect(e?.message).toBe("No secret provided"); } }); }); ================================================ FILE: src/__tests__/services/request.test.ts ================================================ import nock from "nock"; import { TokenModule } from "../../modules/Token.module"; import { Token, TokenScopeType } from "../../models"; describe("Request service test", () => { const token = new Token("token1", [TokenScopeType.EMAIL_FULL, TokenScopeType.ANALYTICS_FULL], "domain_id_test"); const tokenModule = new TokenModule("test_key", "http://test.com"); it("exception", async () => { nock("http://test.com").post("/token").reply(500, { key1: "test_exception" }, { header1: "test_exp" }); try { await tokenModule.create(token); expect(true).toBeFalsy(); } catch (e) { const exception = e as any; expect(exception.headers).toMatchObject({ header1: "test_exp", "content-type": "application/json" }); expect(exception.body).toMatchObject({ key1: "test_exception" }); expect(exception.statusCode).toBe(500); } }); }); ================================================ FILE: src/index.ts ================================================ export * from "./modules/MailerSend.module"; export * from "./models"; ================================================ FILE: src/models/BlocklistMonitor.ts ================================================ import { Pagination } from "./Pagination"; export interface BlocklistMonitorQueryParams extends Pagination { query?: string; sort_by?: 'name' | 'address' | 'created_at' | 'updated_at' | 'blocklisted'; order?: 'asc' | 'desc'; } export class BlocklistMonitor { address: string; name?: string; notify?: boolean; notify_email?: string; notify_address?: string; constructor(address: string) { this.address = address; } setAddress(address: string): BlocklistMonitor { this.address = address; return this; } setName(name: string): BlocklistMonitor { this.name = name; return this; } setNotify(notify: boolean): BlocklistMonitor { this.notify = notify; return this; } setNotifyEmail(notifyEmail: string): BlocklistMonitor { this.notify_email = notifyEmail; return this; } setNotifyAddress(notifyAddress: string): BlocklistMonitor { this.notify_address = notifyAddress; return this; } } export interface BlocklistMonitorUpdate { name?: string; notify?: boolean; notify_email?: string; notify_address?: string; } ================================================ FILE: src/models/EmailVerification.ts ================================================ import { Pagination } from "./Pagination"; export interface EmailVerificationQueryParams extends Pagination {} export interface EmailVerificationSingleQueryParams { detailed?: boolean; page?: number; limit?: number; } export interface EmailVerificationResultQueryParams extends Pagination { results?: EmailVerificationResultType[]; } export class EmailVerification { name: string; emails: string[]; list_id?: string; verify?: boolean; constructor( name: string, emails: string[], ) { this.name = name; this.emails = emails; } setName(name: string): EmailVerification { this.name = name; return this; } setEmails(emails: string[]): EmailVerification { this.emails = emails; return this; } setListId(listId: string): EmailVerification { this.list_id = listId; return this; } setVerify(verify: boolean): EmailVerification { this.verify = verify; return this; } } export enum EmailVerificationResultType { VALID = 'valid', CATCH_ALL = 'catch_all', MAILBOX_FULL = 'mailbox_full', ROLE_BASED = 'role_based', UNKNOWN = 'unknown', SYNTAX_ERROR = 'syntax_error', TYPO = 'typo', MAILBOX_NOT_FOUND = 'mailbox_not_found', DISPOSABLE = 'disposable', MAILBOX_BLOCKED = 'mailbox_blocked', FAILED = 'failed', } ================================================ FILE: src/models/Pagination.ts ================================================ export interface Pagination { page?: number; limit?: number; } ================================================ FILE: src/models/Token.ts ================================================ export class Token { name: string; domain_id?: string; scopes: TokenScopeType[]; constructor(name: string, scopes: TokenScopeType[], domainId?: string) { this.name = name; this.scopes = scopes; this.domain_id = domainId; } setName(name: string): Token { this.name = name; return this } setDomainId(domainId: string): Token { this.domain_id = domainId; return this } setScopes(scopes: TokenScopeType[]): Token { this.scopes = scopes; return this } } export enum TokenScopeType { EMAIL_FULL = "email_full", DOMAINS_FULL = "domains_full", ACTIVITY_READ = "activity_read", ACTIVITY_FULL = "activity_full", ANALYTICS_READ = "analytics_read", ANALYTICS_FULL = "analytics_full", TOKENS_FULL = "tokens_full", WEBHOOKS_FULL = "webhooks_full", TEMPLATES_FULL = "templates_full", SUPPRESSIONS_READ = 'suppressions_read', SUPPRESSIONS_FULL = 'suppressions_full', SMS_READ = 'sms_read', SMS_FULL = 'sms_full', EMAIL_VERIFICATION_READ = 'email_verification_read', EMAIL_VERIFICATION_FULL = 'email_verification_full', INBOUNDS_FULL = 'inbounds_full', RECIPIENTS_READ = 'recipients_read', RECIPIENTS_FULL = 'recipients_full', DOMAINS_READ = "domains_read", SENDER_IDENTITY_READ = "sender_identity_read", SENDER_IDENTITY_FULL = "sender_identity_full", USERS_READ = "users_read", USERS_FULL = "users_full", SMTP_USERS_READ = "smtp_users_read", SMTP_USERS_FULL = "smtp_users_full", DMARC_MONITORING_READ = "dmarc_monitoring_read", DMARC_MONITORING_FULL = "dmarc_monitoring_full", BLOCKLIST_MONITORING_READ = "blocklist_monitoring_read", BLOCKLIST_MONITORING_FULL = "blocklist_monitoring_full", WHATSAPP_FULL = "whatsapp_full", IFTTT = "ifttt", } export interface TokenUpdates { name?: string; status?: "pause" | "unpause"; } ================================================ FILE: src/models/User.ts ================================================ import { Pagination } from "./Pagination"; export interface UserQueryParams extends Pagination {} export interface UserCreate { email: string; role: UserRole | string; permissions?: UserPermission[] | string[]; templates?: string[]; domains?: string[]; requires_periodic_password_change?: boolean; } export interface UserUpdate { role?: UserRole | string; permissions?: UserPermission[] | string[]; templates?: string[]; domains?: string[]; requires_periodic_password_change?: boolean; } export interface InviteQueryParams extends Pagination {} export enum UserRole { Admin = 'Admin', Manager = 'Manager', Designer = 'Designer', Accountant = 'Accountant', CustomUser = 'Custom User', } export enum UserPermission { ReadAllTemplates = 'read-all-templates', ReadOwnTemplates = 'read-own-templates', ManageTemplates = 'manage-template', ReadFilemanager = 'read-filemanager', ManageDomain = 'manage-domain', ManageInbound = 'manage-inbound', ManageWebhook = 'manage-webhook', ControlSendings = 'control-sendings', ControlTrackingOptions = 'control-tracking-options', AccessSmtpCredentials = 'access-smtp-credentials', ViewSmtpUsers = 'view-smtp-users', ManageSmtpUsers = 'manage-smtp-users', ReadRecipient = 'read-recipient', ReadActivity = 'read-activity', ReadEmail = 'read-email', ReadAnalytics = 'read-analytics', ReadSenderIdentities = 'read-sender-identities', ManageSenderIdentities = 'manage-sender-identities', ReadEmailVerification = 'read-email-verification', ManageEmailVerification = 'manage-email-verification', ManageSms = 'manage-sms', ReadSms = 'read-sms', ManageVerifiedRecipients = 'manage-verified-recipients', ViewSmsWebhooks = 'view-sms-webhooks', ManageSmsWebhooks = 'manage-sms-webhooks', ViewSmsInbound = 'view-sms-inbound', ManageSmsInbound = 'manage-sms-inbound', UpdatePlan = 'update-plan', ManageAccount = 'manage-account', ReadInvoice = 'read-invoice', ManageApiToken = 'manage-api-token', ReadSuppressions = 'read-suppressions', ManageSuppressions = 'manage-suppressions', ReadIpAddresses = 'read-ip-addresses', ManageIpAddresses = 'manage-ip-addresses', ReadErrorLog = 'read-error-log', } ================================================ FILE: src/models/email/Activity.ts ================================================ import { Pagination } from "../Pagination"; export interface ActivityQueryParams extends Pagination { date_from: number | string; date_to: number | string; event?: ActivityEventType[]; } export enum ActivityEventType { QUEUED = "queued", SENT = "sent", DELIVERED = "delivered", SOFT_BOUNCED = "soft_bounced", HARD_BOUNCED = "hard_bounced", OPENED = "opened", OPENED_UNIQUE = "opened_unique", CLICKED = "clicked", CLICKED_UNIQUE = "clicked_unique", UNSUBSCRIBED = "unsubscribed", SPAM_COMPLAINTS = "spam_complaints", SURVEY_OPENED = "survey_opened", SURVEY_SUBMITTED = "survey_submitted", DEFERRED = "deferred", } ================================================ FILE: src/models/email/Analytics.ts ================================================ import { ActivityEventType } from "./Activity"; export interface AnalyticsOpensQueryParams { date_from: number; date_to: number; recipient_id?: string[]; tags?: string[]; domain_id?: string; } export interface AnalyticsDateQueryParams extends AnalyticsOpensQueryParams { group_by?: AnalyticsGroupByType; event?: ActivityEventType[]; } export enum AnalyticsGroupByType { DAYS = "days", WEEKS = "weeks", MONTHS = "months", YEARS = "years" } ================================================ FILE: src/models/email/Attachment.ts ================================================ export class Attachment { content: string; filename: string; disposition: 'inline' | 'attachment'; id?: string; constructor(content: string, fileName: string, disposition: 'inline' | 'attachment' = "attachment", id?: string) { this.content = content; this.filename = fileName; this.disposition = disposition; this.id = id; } } ================================================ FILE: src/models/email/Dmarc.ts ================================================ import { Pagination } from "../Pagination"; export class Dmarc { domain_id: string; constructor(domainId: string) { this.domain_id = domainId; } } export interface DmarcQueryParams extends Pagination { query?: string; sort_by?: 'created_at' | 'updated_at' | 'dmarc_valid' | 'spf_status'; order?: 'asc' | 'desc'; } export interface DmarcReportQueryParams extends Pagination { date_from?: string; date_to?: string; search?: string; category?: string; report_source?: string; } export interface DmarcReportSourcesQueryParams { date_from: string; date_to: string; status?: 'accepted' | 'rejected' | 'quarantined'; } export interface DmarcUpdate { wanted_dmarc_record: string; } ================================================ FILE: src/models/email/Domain.ts ================================================ import { Pagination } from "../Pagination"; export class Domain { name: string; return_path_subdomain?: string; custom_tracking_subdomain?: string; inbound_routing_subdomain?: string; constructor( name: string, returnPathSubdomain?: string, customTrackingSubdomain?: string, inboundRoutingSubdomain?: string, ) { this.name = name; this.return_path_subdomain = returnPathSubdomain; this.custom_tracking_subdomain = customTrackingSubdomain; this.inbound_routing_subdomain = inboundRoutingSubdomain; } } export interface DomainQueryParams extends Pagination { verified?: boolean; } export interface DomainRecipientsQueryParams extends Pagination {} export interface DomainSettings { send_paused?: boolean; track_clicks?: boolean; track_opens?: boolean; track_unsubscribe?: boolean; track_unsubscribe_html?: string; track_unsubscribe_plain?: string; track_unsubscribe_html_enabled?: boolean; track_unsubscribe_plain_enabled?: boolean; track_content?: boolean; custom_tracking_enabled?: boolean; custom_tracking_subdomain?: string; precedence_bulk?: boolean; ignore_duplicated_recipients?: boolean; } ================================================ FILE: src/models/email/EmailParams.ts ================================================ import { Recipient } from "./Recipient"; import { Sender } from "./Sender"; import { Attachment } from "./Attachment"; import { Personalization } from "../../modules/Email.module"; export class EmailParams { from?: Sender; to: Recipient[]; cc?: Recipient[]; bcc?: Recipient[]; rcpt_to?: Recipient[]; reply_to?: Recipient; subject?: string; text?: string; html?: string; send_at?: number | string; attachments?: Attachment[]; template_id?: string; in_reply_to?: string; references?: string[]; tags?: string[]; personalization?: Personalization[]; headers?: EmailHeader[]; settings?: EmailSettings; precedence_bulk?: boolean; list_unsubscribe?: string; constructor(config?: any) { this.from = config?.from; this.to = config?.to; this.cc = config?.cc; this.bcc = config?.bcc; this.rcpt_to = config?.rcptTo; this.reply_to = config?.replyTo; this.in_reply_to = config?.inReplyTo; this.subject = config?.subject; this.text = config?.text; this.html = config?.html; this.send_at = config?.sendAt; this.attachments = config?.attachments; this.template_id = config?.templateId; this.tags = config?.tags; this.personalization = config?.personalization; this.references = config?.references; this.headers = config?.headers; this.settings = config?.settings; this.precedence_bulk = config?.precedenceBulk; this.list_unsubscribe = config?.listUnsubscribe; } setFrom(from: Sender): EmailParams { this.from = from; return this; } setTo(to: Recipient[]): EmailParams { this.to = to; return this; } setCc(cc: Recipient[]): EmailParams { this.cc = cc; return this; } setBcc(bcc: Recipient[]): EmailParams { this.bcc = bcc; return this; } setRcptTo(rcptTo: Recipient[]): EmailParams { this.rcpt_to = rcptTo; return this; } setReplyTo(replyTo: Recipient): EmailParams { this.reply_to = replyTo; return this; } setInReplyTo(inReplyTo: string): EmailParams { this.in_reply_to = inReplyTo; return this; } setSubject(subject: string): EmailParams { this.subject = subject; return this; } setText(text: string): EmailParams { this.text = text; return this; } setHtml(html: string): EmailParams { this.html = html; return this; } setSendAt(sendAt: number | string): EmailParams { this.send_at = sendAt; return this; } setAttachments(attachments: Attachment[]): EmailParams { this.attachments = attachments; return this; } setTemplateId(id: string): EmailParams { this.template_id = id; return this; } setTags(tags: string[]): EmailParams { this.tags = tags; return this; } setPersonalization(personalization: Personalization[]): EmailParams { this.personalization = personalization; return this; } setPrecedenceBulk(precedenceBulk: boolean): EmailParams { this.precedence_bulk = precedenceBulk; return this; } setSettings(settings: EmailSettings): EmailParams { this.settings = settings; return this; } setReferences(references: string[]): EmailParams { this.references = references; return this; } setHeaders(headers: EmailHeader[]): EmailParams { this.headers = headers; return this; } setListUnsubscribe(listUnsubscribe: string): EmailParams { this.list_unsubscribe = listUnsubscribe; return this; } } export interface EmailSettings { track_clicks?: boolean; track_opens?: boolean; track_content?: boolean; } export interface EmailHeader { name: string; value: string; } ================================================ FILE: src/models/email/EmailWebhook.ts ================================================ export class EmailWebhook { url!: string; name!: string; events!: EmailWebhookEventType[]; domain_id!: string; enabled?: boolean; version?: number; editable?: boolean; constructor(config?: IEmailWebhook) { if (config) { this.url = config.url; this.name = config.name; this.events = config.events; this.domain_id = config.domain_id; this.enabled = config.enabled; this.version = config.version; this.editable = config.editable; } } setUrl(url: string): EmailWebhook { this.url = url; return this; } setName(name: string): EmailWebhook { this.name = name; return this; } setEvents(events: any[]): EmailWebhook { this.events = events; return this; } /** * Set domain id * @param domainId - Existing hashed domain ID. */ setDomainId(domainId: string): EmailWebhook { this.domain_id = domainId; return this; } setEnabled(enabled: boolean): EmailWebhook { this.enabled = enabled; return this; } setEditable(editable: boolean): EmailWebhook { this.editable = editable; return this; } setVersion(version: 1 | 2): EmailWebhook { this.version = version; return this; } } export enum EmailWebhookEventType { SENT = "activity.sent", DELIVERED = "activity.delivered", SOFT_BOUNCED = "activity.soft_bounced", HARD_BOUNCED = "activity.hard_bounced", OPENED = "activity.opened", OPENED_UNIQUE = "activity.opened_unique", CLICKED = "activity.clicked", CLICKED_UNIQUE = "activity.clicked_unique", UNSUBSCRIBED = "activity.unsubscribed", SPAM_COMPLAINT = "activity.spam_complaint", SURVEY_OPENED = "activity.survey_opened", SURVEY_SUBMITTED = "activity.survey_submitted", IDENTITY_VERIFIED = "sender_identity.verified", MAINTENANCE_START = "maintenance.start", MAINTENANCE_END = "maintenance.end", DEFERRED = "activity.deferred", INBOUND_FORWARD_FAILED = "inbound_forward.failed", EMAIL_SINGLE_VERIFIED = "email_single.verified", EMAIL_LIST_VERIFIED = "email_list.verified", BULK_EMAIL_COMPLETED = "bulk_email.completed", RECIPIENT_ON_HOLD_ADDED = "recipient.on_hold_added", RECIPIENT_ON_HOLD_REMOVED = "recipient.on_hold_removed", } export interface IEmailWebhook extends IEmailWebhookUpdate { domain_id: string; } export interface IEmailWebhookUpdate { url: string; name: string; events: EmailWebhookEventType[]; enabled?: boolean; version?: number; editable?: boolean; } export interface IEmailWebhookUpdateParams { url?: string; name?: string; events?: EmailWebhookEventType[]; enabled?: boolean; version?: number; editable?: boolean; } ================================================ FILE: src/models/email/Identity.ts ================================================ import { Pagination } from "../Pagination"; export class Identity { domain_id: string; email: string; name?: string; personal_note?: string; reply_to_name?: string; reply_to_email?: string; add_note?: boolean; constructor( domainId: string, email: string, name?: string, personalNote?: string, replyToName?: string, replyToEmail?: string, addNote?: boolean, ) { this.domain_id = domainId; this.email = email; this.name = name; this.personal_note = personalNote; this.reply_to_name = replyToName; this.reply_to_email = replyToEmail; this.add_note = addNote; } setDomainId(domainId: string): Identity { this.domain_id = domainId; return this; } setEmail(email: string): Identity { this.email = email; return this; } setName(name: string): Identity { this.name = name; return this; } setPersonalNote(personalNote: string): Identity { this.personal_note = personalNote; return this; } setReplyToName(replyToName: string): Identity { this.reply_to_name = replyToName; return this; } setReplyToEmail(replyToEmail: string): Identity { this.reply_to_email = replyToEmail; return this; } setAddNote(addNote: boolean): Identity { this.add_note = addNote; return this; } } export interface IdentityQueryParams extends Pagination { domain_id?: string; query?: string; order_by?: 'email' | 'created_at' | 'verified_at'; order?: 'asc' | 'desc'; } export interface IdentityUpdate { name?: string; reply_to_email?: string; reply_to_name?: string; } ================================================ FILE: src/models/email/Inbound.ts ================================================ import { Pagination } from "../Pagination"; export interface InboundQueryParams extends Pagination { domain_id?: string; } export class Inbound { name: string; domain_enabled: boolean; domain_id: string; inbound_domain?: string; inbound_priority?: number; catch_type?: 'all' | 'one'; match_type?: 'all' | 'one'; forwards?: InboundForward[]; match_filter?: MatchFilter; catch_filter?: CatchFilter; constructor( name: string, domainEnabled: boolean, domainId: string, inboundDomain?: string, inboundPriority?: number, forwards?: InboundForward[], matchFilter?: MatchFilter, catchFilter?: CatchFilter, ) { this.name = name; this.domain_enabled = domainEnabled; this.domain_id = domainId; this.inbound_domain = inboundDomain; this.inbound_priority = inboundPriority; this.forwards = forwards; this.match_filter = matchFilter; this.catch_filter = catchFilter; } setDomainId(domainId: string): Inbound { this.domain_id = domainId; return this; } setName(name: string): Inbound { this.name = name; return this; } setDomainEnabled(domainEnabled: boolean): Inbound { this.domain_enabled = domainEnabled; return this; } setInboundDomain(inboundDomain: string): Inbound { this.inbound_domain = inboundDomain; return this; } setInboundPriority(inboundPriority: number): Inbound { this.inbound_priority = inboundPriority; return this; } setForwards(forwards: InboundForward[]): Inbound { this.forwards = forwards; return this; } setMatchFilter(matchFilter: MatchFilter): Inbound { this.match_filter = matchFilter; return this; } setCatchFilter(catchFilter: CatchFilter): Inbound { this.catch_filter = catchFilter; return this; } } export class InboundUpdateParams { name: string; domain_enabled: boolean; inbound_domain?: string; inbound_priority?: number; catch_type?: 'all' | 'one'; match_type?: 'all' | 'one'; forwards?: InboundForward[]; match_filter?: MatchFilter; catch_filter?: CatchFilter; constructor( name: string, domainEnabled: boolean, inboundDomain?: string, inboundPriority?: number, forwards?: InboundForward[], matchFilter?: MatchFilter, catchFilter?: CatchFilter, ) { this.name = name; this.domain_enabled = domainEnabled; this.inbound_domain = inboundDomain; this.inbound_priority = inboundPriority; this.forwards = forwards; this.match_filter = matchFilter; this.catch_filter = catchFilter; } setName(name: string): InboundUpdateParams { this.name = name; return this; } setDomainEnabled(domainEnabled: boolean): InboundUpdateParams { this.domain_enabled = domainEnabled; return this; } setInboundDomain(inboundDomain: string): InboundUpdateParams { this.inbound_domain = inboundDomain; return this; } setInboundPriority(inboundPriority: number): InboundUpdateParams { this.inbound_priority = inboundPriority; return this; } setForwards(forwards: InboundForward[]): InboundUpdateParams { this.forwards = forwards; return this; } setMatchFilter(matchFilter: MatchFilter): InboundUpdateParams { this.match_filter = matchFilter; return this; } setCatchFilter(catchFilter: CatchFilter): InboundUpdateParams { this.catch_filter = catchFilter; return this; } } export interface InboundForward { type: 'webhook' | 'email'; value: string; } export enum InboundFilterType { CATCH_ALL = 'catch_all', CATCH_RECIPIENT = 'catch_recipient', MATCH_ALL = 'match_all', MATCH_SENDER = 'match_sender', MATCH_DOMAIN = 'match_domain', MATCH_HEADER = 'match_header', } export enum ComparerType { EQUAL = 'equal', NOT_EQUAL = 'not-equal', CONTAINS = 'contains', NOT_CONTAINS = 'not-contains', STARTS_WITH = 'starts-with', ENDS_WITH = 'ends-with', NOT_STARTS_WITH = 'not-starts-with', NOT_ENDS_WITH = 'not-ends-with', } export interface InboundFilter { comparer: ComparerType; value: string; } export interface MatchInboundFilter extends InboundFilter { key?: string; } export interface CatchFilter { type: InboundFilterType; filters?: InboundFilter[]; } export interface MatchFilter { type: InboundFilterType; filters?: MatchInboundFilter[]; } ================================================ FILE: src/models/email/Message.ts ================================================ import { Pagination } from "../Pagination"; export interface MessageQueryParams extends Pagination {} ================================================ FILE: src/models/email/Recipient.ts ================================================ import { Sender } from "./Sender"; import { Pagination } from "../Pagination"; export class Recipient extends Sender { constructor(email: string, name?: string) { super(email, name); } } export interface RecipientsQueryParams extends Pagination { domain_id?: string; } export interface BlockListQueryParams extends Pagination { domain_id?: string; } export interface OnHoldListQueryParams extends Pagination { domain_id?: string; } export interface BlockListRecipients { domain_id?: string; recipients?: string[]; patterns?: string[]; } export interface BlockListRecipientsPost { domain_id: string; recipients: string[]; } export enum BlockListType { BLOCK_LIST = 'blocklist', HARD_BOUNCES_LIST = 'hard-bounces', SPAM_COMPLAINTS_LIST = 'spam-complaints', UNSUBSCRIBES_LIST = 'unsubscribes', ON_HOLD_LIST = 'on-hold-list', } ================================================ FILE: src/models/email/Schedule.ts ================================================ import { Pagination } from "../Pagination"; export interface ScheduleQueryParams extends Pagination { domain_id?: string; status?: 'scheduled' | 'sent' | 'error'; } ================================================ FILE: src/models/email/Sender.ts ================================================ export class Sender { email: string; name?: string; constructor(email: string, name?: string) { this.email = email; this.name = name; } } ================================================ FILE: src/models/email/SmtpUser.ts ================================================ import { Pagination } from "../Pagination"; export interface SmtpUserParams { name: string; enabled?: boolean; } export interface SmtpUserQueryParams extends Pagination {} ================================================ FILE: src/models/email/Template.ts ================================================ import { Pagination } from "../Pagination"; export interface TemplateQueryParams extends Pagination { domain_id?: string; } export interface TemplateParams { name?: string; categories?: string[]; domain_id?: string; tags?: string[]; text: string; html: string; auto_generate?: boolean; } export interface TemplateUpdateParams { name?: string; categories?: string[]; domain_id?: string; tags?: string[]; text?: string; html?: string; auto_generate?: boolean; } ================================================ FILE: src/models/index.ts ================================================ export * from "./Token"; export * from "./EmailVerification"; export * from "./Pagination"; export * from "./User"; export * from "./BlocklistMonitor"; //Email Models export * from "./email/Attachment"; export * from "./email/EmailParams"; export * from "./email/EmailWebhook"; export * from "./email/Recipient"; export * from "./email/Sender"; export * from "./email/Activity"; export * from "./email/Analytics"; export * from "./email/Domain"; export * from "./email/SmtpUser"; export * from "./email/Inbound"; export * from "./email/Message"; export * from "./email/Schedule"; export * from "./email/Template"; export * from "./email/Identity"; export * from "./email/Dmarc"; //SMS Models export * from "./sms/Activity"; export * from "./sms/Message"; export * from "./sms/Number"; export * from "./sms/Inbound"; export * from "./sms/SMSParams"; export * from "./sms/SMSPersonalization"; export * from "./sms/Recipient"; export * from "./sms/Webhook"; ================================================ FILE: src/models/sms/Activity.ts ================================================ import { Pagination } from "../Pagination"; export interface SmsActivityQueryParams extends Pagination { date_from?: number; date_to?: number; status?: SmsActivityStatusType[]; sms_number_id?: string; } export enum SmsActivityStatusType { QUEUED = "queued", SENT = "sent", DELIVERED = "delivered", FAILED = "failed", PROCESSED = "processed", } ================================================ FILE: src/models/sms/Inbound.ts ================================================ import { Pagination } from "../Pagination"; export interface SmsInboundQueryParams extends Pagination { sms_number_id?: string; enabled?: boolean; } export class SmsInbound { name: string; enabled?: boolean; sms_number_id?: string; forward_url: string; filter?: SmsInboundFilter; constructor( name: string, smsNumberId: string, forwardUrl: string, enabled?: boolean, filter?: SmsInboundFilter, ) { this.name = name; this.enabled = enabled; this.sms_number_id = smsNumberId; this.forward_url = forwardUrl; this.filter = filter; } setSmsNumberId(smsNumberId: string): SmsInbound { this.sms_number_id = smsNumberId; return this; } setName(name: string): SmsInbound { this.name = name; return this; } setEnabled(enabled: boolean): SmsInbound { this.enabled = enabled; return this; } setForwardUrl(forward_url: string): SmsInbound { this.forward_url = forward_url; return this; } setFilter(filter: SmsInboundFilter): SmsInbound { this.filter = filter; return this; } } export enum SmsComparerType { EQUAL = 'equal', NOT_EQUAL = 'not-equal', CONTAINS = 'contains', NOT_CONTAINS = 'not-contains', STARTS_WITH = 'starts-with', ENDS_WITH = 'ends-with', NOT_STARTS_WITH = 'not-starts-with', NOT_ENDS_WITH = 'not-ends-with', } export interface SmsInboundFilter { comparer: SmsComparerType; value: string; } export interface SmsInboundUpdate { name?: string; enabled?: boolean; sms_number_id?: string; forward_url?: string; filter?: SmsInboundFilter; } ================================================ FILE: src/models/sms/Message.ts ================================================ import { Pagination } from "../Pagination"; export interface SmsMessageQueryParams extends Pagination {} ================================================ FILE: src/models/sms/Number.ts ================================================ import { Pagination } from "../Pagination"; export interface SmsNumberQueryParams extends Pagination { paused?: boolean; } ================================================ FILE: src/models/sms/Recipient.ts ================================================ import { Pagination } from "../Pagination"; export interface SmsRecipientQueryParams extends Pagination { status?: "active" | "opt_out"; sms_number_id?: string; } ================================================ FILE: src/models/sms/SMSParams.ts ================================================ import { SMSPersonalization } from "./SMSPersonalization"; export class SMSParams { from: string; to: string[]; text: string; personalization?: SMSPersonalization[]; constructor(config?: any) { this.from = config?.from; this.to = config?.to; this.text = config?.text; if (config?.personalization?.length) { this.personalization = config?.personalization; } } setFrom(from: string): SMSParams { this.from = from; return this; } setTo(to: string[]): SMSParams { this.to = to; return this; } setText(text: string): SMSParams { this.text = text; return this; } setPersonalization(personalization: SMSPersonalization[]): SMSParams { this.personalization = personalization; return this; } } ================================================ FILE: src/models/sms/SMSPersonalization.ts ================================================ export class SMSPersonalization { phone_number: string; data: { [key: string]: string; }; constructor(phoneNumber: string, data: { [key: string]: string }) { this.phone_number = phoneNumber; this.data = data; } } ================================================ FILE: src/models/sms/Webhook.ts ================================================ export interface SmsWebhookQueryParams { sms_number_id: string; page?: number; limit?: number; } export class SmsWebhook { url: string; name: string; events: SmsWebhookEventType[]; sms_number_id: string; enabled?: boolean; constructor( name: string, url: string, events: SmsWebhookEventType[], smsNumberId: string, enabled?: boolean ) { this.url = url; this.name = name; this.events = events; this.sms_number_id = smsNumberId; this.enabled = enabled; } setUrl(url: string): SmsWebhook { this.url = url; return this; } setName(name: string): SmsWebhook { this.name = name; return this; } setEvents(events: SmsWebhookEventType[]): SmsWebhook { this.events = events; return this; } setSmsNumberId(smsNumberId: string): SmsWebhook { this.sms_number_id = smsNumberId; return this; } setEnabled(enabled: boolean): SmsWebhook { this.enabled = enabled; return this; } } export interface SmsWebhookUpdate { url?: string; name?: string; events?: SmsWebhookEventType[]; enabled?: boolean; } export enum SmsWebhookEventType { SENT = "sms.sent", DELIVERED = "sms.delivered", FAILED = "sms.failed", } ================================================ FILE: src/modules/BlocklistMonitor.module.ts ================================================ import { RequestService, APIResponse } from "../services/request.service"; import { BlocklistMonitor, BlocklistMonitorQueryParams, BlocklistMonitorUpdate } from "../models"; export class BlocklistMonitorModule extends RequestService { constructor(apiKey: string, baseUrl: string) { super(apiKey, baseUrl); } async list(queryParams?: BlocklistMonitorQueryParams): Promise { return await this.get(`/blocklist-monitoring`, queryParams); } async single(monitorId: string): Promise { return await this.get(`/blocklist-monitoring/${monitorId}`); } async create(data: BlocklistMonitor): Promise { return await this.post(`/blocklist-monitoring`, data); } async update(monitorId: string, data: BlocklistMonitorUpdate): Promise { return await this.put(`/blocklist-monitoring/${monitorId}`, data); } async delete(monitorId: string): Promise { return await this.deleteReq(`/blocklist-monitoring/${monitorId}`); } } ================================================ FILE: src/modules/Dmarc.module.ts ================================================ import { RequestService, APIResponse } from "../services/request.service"; import { Dmarc, DmarcQueryParams, DmarcReportQueryParams, DmarcReportSourcesQueryParams, DmarcUpdate } from "../models"; export class DmarcModule extends RequestService { constructor(apiKey: string, baseUrl: string) { super(apiKey, baseUrl); } async list(queryParams?: DmarcQueryParams): Promise { return await this.get(`/dmarc-monitoring`, queryParams); } async create(data: Dmarc): Promise { return await this.post(`/dmarc-monitoring`, data); } async update(monitorId: string, data: DmarcUpdate): Promise { return await this.put(`/dmarc-monitoring/${monitorId}`, data); } async delete(monitorId: string): Promise { return await this.deleteReq(`/dmarc-monitoring/${monitorId}`); } async report(monitorId: string, queryParams?: DmarcReportQueryParams): Promise { return await this.get(`/dmarc-monitoring/${monitorId}/report`, queryParams); } async reportByIp(monitorId: string, ip: string, queryParams?: DmarcReportQueryParams): Promise { return await this.get(`/dmarc-monitoring/${monitorId}/report/${ip}`, queryParams); } async reportSources(monitorId: string, queryParams: DmarcReportSourcesQueryParams): Promise { return await this.get(`/dmarc-monitoring/${monitorId}/report-sources`, queryParams); } async addFavorite(monitorId: string, ip: string): Promise { return await this.put(`/dmarc-monitoring/${monitorId}/favorite/${ip}`, {}); } async removeFavorite(monitorId: string, ip: string): Promise { return await this.deleteReq(`/dmarc-monitoring/${monitorId}/favorite/${ip}`); } } ================================================ FILE: src/modules/Email.module.ts ================================================ import { EmailParams } from "../models"; import { RequestService, APIResponse } from "../services/request.service"; import { ActivityModule } from "./email/Activity.module"; import { AnalyticsModule } from "./email/Analytics.module"; import { DomainModule } from "./email/Domain.module"; import { InboundModule } from "./email/Inbound.module"; import { MessageModule } from "./email/Message.module"; import { ScheduleModule } from "./email/Schedule.module"; import { RecipientModule } from "./email/Recipient.module"; import { TemplateModule } from "./email/Template.module"; import { EmailWebhookModule } from "./email/Webhook.module"; import { IdentityModule } from "./email/Identity.module"; import { SmtpUserModule } from "./email/SmtpUser.module"; export class EmailModule extends RequestService { activity: ActivityModule; analytics: AnalyticsModule; domain: DomainModule; inbound: InboundModule; message: MessageModule; schedule: ScheduleModule; recipient: RecipientModule; template: TemplateModule; webhook: EmailWebhookModule; identity: IdentityModule; smtpUser: SmtpUserModule; constructor(apiKey: string, baseUrl: string) { super(apiKey, baseUrl); this.activity = new ActivityModule(apiKey, baseUrl); this.analytics = new AnalyticsModule(apiKey, baseUrl); this.domain = new DomainModule(apiKey, baseUrl); this.inbound = new InboundModule(apiKey, baseUrl); this.message = new MessageModule(apiKey, baseUrl); this.schedule = new ScheduleModule(apiKey, baseUrl); this.recipient = new RecipientModule(apiKey, baseUrl); this.template = new TemplateModule(apiKey, baseUrl); this.webhook = new EmailWebhookModule(apiKey, baseUrl); this.identity = new IdentityModule(apiKey, baseUrl); this.smtpUser = new SmtpUserModule(apiKey, baseUrl); } async send(params: EmailParams): Promise { return await this.post("/email", params); } async sendBulk(params: EmailParams[]): Promise { return await this.post("/bulk-email", params); } async getBulkStatus(bulkId: string): Promise { return await this.get(`/bulk-email/${bulkId}`); } } export interface Personalization { email: string; data: { [key: string]: any; }; } ================================================ FILE: src/modules/EmailVerification.module.ts ================================================ import { RequestService, APIResponse } from "../services/request.service"; import { EmailVerification, EmailVerificationQueryParams, EmailVerificationResultQueryParams, EmailVerificationSingleQueryParams } from "../models"; export class EmailVerificationModule extends RequestService { constructor(apiKey: string, baseUrl: string) { super(apiKey, baseUrl); } async list(queryParams?: EmailVerificationQueryParams): Promise { return await this.get(`/email-verification`, queryParams); } async single(emailVerificationId: string, queryParams?: EmailVerificationSingleQueryParams): Promise { return await this.get(`/email-verification/${emailVerificationId}`, queryParams); } async create(emailVerification: EmailVerification): Promise { return await this.post(`/email-verification`, emailVerification); } async verifyList(emailVerificationId: string): Promise { return await this.get(`/email-verification/${emailVerificationId}/verify`); } async getListResult(emailVerificationId: string, queryParams: EmailVerificationResultQueryParams): Promise { return await this.get(`/email-verification/${emailVerificationId}/results`, queryParams); } async verifyEmail(email: string): Promise { return await this.post<{ email: string }>(`/email-verification/verify`, { email: email }); } async verifyEmailAsync(email: string): Promise { return await this.post<{ email: string }>(`/email-verification/verify-async`, { email: email }); } async getVerifyEmailAsyncStatus(id: string): Promise { return await this.get(`/email-verification/verify-async/${id}`); } } ================================================ FILE: src/modules/MailerSend.module.ts ================================================ import { EmailModule } from "./Email.module"; import { TokenModule } from "./Token.module"; import { EmailVerificationModule } from "./EmailVerification.module"; import { SMSModule } from "./SMS.module"; import { OthersModule } from "./Others.module"; import { DmarcModule } from "./Dmarc.module"; import { UserModule } from "./User.module"; import { BlocklistMonitorModule } from "./BlocklistMonitor.module"; export class MailerSend { private readonly apiKey: string; private baseUrl: string = "https://api.mailersend.com/v1"; sms: SMSModule; token: TokenModule; email: EmailModule; emailVerification: EmailVerificationModule; others: OthersModule; dmarc: DmarcModule; user: UserModule; blocklistMonitor: BlocklistMonitorModule; constructor(config: MailerSendConfig) { this.apiKey = config.apiKey; this.token = new TokenModule(config.apiKey, this.baseUrl); this.email = new EmailModule(config.apiKey, this.baseUrl); this.emailVerification = new EmailVerificationModule(config.apiKey, this.baseUrl); this.sms = new SMSModule(config.apiKey, this.baseUrl); this.others = new OthersModule(config.apiKey, this.baseUrl); this.dmarc = new DmarcModule(config.apiKey, this.baseUrl); this.user = new UserModule(config.apiKey, this.baseUrl); this.blocklistMonitor = new BlocklistMonitorModule(config.apiKey, this.baseUrl); } } export interface MailerSendConfig { apiKey: string; } ================================================ FILE: src/modules/Others.module.ts ================================================ import { RequestService, APIResponse } from "../services/request.service"; export class OthersModule extends RequestService { constructor(apiKey: string, baseUrl: string) { super(apiKey, baseUrl); } async getApiQuota(): Promise { return await this.get("/api-quota"); } } ================================================ FILE: src/modules/SMS.module.ts ================================================ import { SMSParams } from "../models"; import { APIResponse, RequestService } from "../services/request.service"; import { SmsActivityModule } from "./sms/Activity.module"; import { SmsInboundModule } from "./sms/Inbound.module"; import { SmsMessageModule } from "./sms/Message.module"; import { SmsNumberModule } from "./sms/Number.module"; import { SmsRecipientModule } from "./sms/Recipient.module"; import { SmsWebhookModule } from "./sms/Webhook.module"; export class SMSModule extends RequestService { activity: SmsActivityModule; number: SmsNumberModule; message: SmsMessageModule; inbound: SmsInboundModule; recipient: SmsRecipientModule; webhook: SmsWebhookModule; constructor(apiKey: string, baseUrl: string) { super(apiKey, baseUrl); this.activity = new SmsActivityModule(apiKey, baseUrl); this.number = new SmsNumberModule(apiKey, baseUrl); this.message = new SmsMessageModule(apiKey, baseUrl); this.inbound = new SmsInboundModule(apiKey, baseUrl); this.recipient = new SmsRecipientModule(apiKey, baseUrl); this.webhook = new SmsWebhookModule(apiKey, baseUrl); } async send(params: SMSParams): Promise { return await this.post("/sms", params); } } ================================================ FILE: src/modules/Token.module.ts ================================================ import { RequestService, APIResponse } from "../services/request.service"; import { Token, TokenUpdates } from "../models"; export class TokenModule extends RequestService { constructor(apiKey: string, baseUrl: string) { super(apiKey, baseUrl); } async list(params?: { page?: number; limit?: number }): Promise { return await this.get(`/token`, params); } async single(tokenId: string): Promise { return await this.get(`/token/${tokenId}`); } async create(token: Token): Promise { return await this.post("/token", token); } async update(tokenId: string, data: { name?: string; status?: "pause" | "unpause" }): Promise { return await this.put(`/token/${tokenId}`, data); } async updateSettings(tokenId: string, updates: TokenUpdates): Promise { return await this.put(`/token/${tokenId}`, updates); } async delete(tokenId: string): Promise { return await this.deleteReq(`/token/${tokenId}`); } } ================================================ FILE: src/modules/User.module.ts ================================================ import { RequestService, APIResponse } from "../services/request.service"; import { UserCreate, UserQueryParams, UserUpdate, InviteQueryParams } from "../models"; export class UserModule extends RequestService { constructor(apiKey: string, baseUrl: string) { super(apiKey, baseUrl); } async list(queryParams?: UserQueryParams): Promise { return await this.get(`/users`, queryParams); } async single(userId: string): Promise { return await this.get(`/users/${userId}`); } async create(data: UserCreate): Promise { return await this.post(`/users`, data); } async update(userId: string, data: UserUpdate): Promise { return await this.put(`/users/${userId}`, data); } async delete(userId: string): Promise { return await this.deleteReq(`/users/${userId}`); } async listInvites(queryParams?: InviteQueryParams): Promise { return await this.get(`/invites`, queryParams); } async singleInvite(inviteId: string): Promise { return await this.get(`/invites/${inviteId}`); } async resendInvite(inviteId: string): Promise { return await this.post(`/invites/${inviteId}/resend`, {}); } async deleteInvite(inviteId: string): Promise { return await this.deleteReq(`/invites/${inviteId}`); } } ================================================ FILE: src/modules/email/Activity.module.ts ================================================ import { ActivityQueryParams } from "../../models"; import { RequestService, APIResponse } from "../../services/request.service"; export class ActivityModule extends RequestService { constructor(apiKey: string, baseUrl: string) { super(apiKey, baseUrl); } async domain(domainId: string, queryParams?: ActivityQueryParams): Promise { return await this.get(`/activity/${domainId}`, queryParams); } async single(activityId: string): Promise { return await this.get(`/activities/${activityId}`); } } ================================================ FILE: src/modules/email/Analytics.module.ts ================================================ import { AnalyticsDateQueryParams, AnalyticsOpensQueryParams } from "../../models"; import { RequestService, APIResponse } from "../../services/request.service"; export class AnalyticsModule extends RequestService { constructor(apiKey: string, baseUrl: string) { super(apiKey, baseUrl); } async byDate(queryParams: AnalyticsDateQueryParams): Promise { return await this.get(`/analytics/date`, queryParams); } async byCountry(queryParams: AnalyticsOpensQueryParams): Promise { return await this.get(`/analytics/country`, queryParams); } async byUserAgent(queryParams: AnalyticsOpensQueryParams): Promise { return await this.get(`/analytics/ua-name`, queryParams); } async byReadingEnvironment(queryParams: AnalyticsOpensQueryParams): Promise { return await this.get(`/analytics/ua-type`, queryParams); } } ================================================ FILE: src/modules/email/Domain.module.ts ================================================ import { RequestService, APIResponse } from "../../services/request.service"; import { Domain, DomainQueryParams, DomainRecipientsQueryParams, DomainSettings } from "../../models"; export class DomainModule extends RequestService { constructor(apiKey: string, baseUrl: string) { super(apiKey, baseUrl); } async create(domain: Domain) { return await this.post(`/domains`, domain); } async list(queryParams?: DomainQueryParams): Promise { return await this.get(`/domains`, queryParams); } async single(domainId: string): Promise { return await this.get(`/domains/${domainId}`); } async delete(domainId: string): Promise { return await this.deleteReq(`/domains/${domainId}`); } async updateSettings(domainId: string, data: DomainSettings): Promise { return await this.put(`/domains/${domainId}/settings`, data); } async recipients(domainId: string, queryParams?: DomainRecipientsQueryParams): Promise { return await this.get(`/domains/${domainId}/recipients`, queryParams); } async dns(domainId: string): Promise { return await this.get(`/domains/${domainId}/dns-records`); } async verify(domainId: string): Promise { return await this.get(`/domains/${domainId}/verify`); } } ================================================ FILE: src/modules/email/Identity.module.ts ================================================ import { RequestService, APIResponse } from "../../services/request.service"; import { Identity, IdentityQueryParams, IdentityUpdate } from "../../models"; export class IdentityModule extends RequestService { constructor(apiKey: string, baseUrl: string) { super(apiKey, baseUrl); } async create(identity: Identity) { return await this.post(`/identities`, identity); } async list(queryParams?: IdentityQueryParams): Promise { return await this.get(`/identities`, queryParams); } async single(identityId: string): Promise { return await this.get(`/identities/${identityId}`); } async singleByEmail(email: string): Promise { return await this.get(`/identities/email/${email}`); } async update(identityId: string, data: IdentityUpdate): Promise { return await this.put(`/identities/${identityId}`, data); } async updateByEMail(email: string, data: IdentityUpdate): Promise { return await this.put(`/identities/email/${email}`, data); } async delete(identityId: string): Promise { return await this.deleteReq(`/identities/${identityId}`); } async deleteByEmail(email: string): Promise { return await this.deleteReq(`/identities/email/${email}`); } async resend(identityId: string): Promise { return await this.post(`/identities/${identityId}/resend`, {}); } } ================================================ FILE: src/modules/email/Inbound.module.ts ================================================ import { RequestService, APIResponse } from "../../services/request.service"; import { Inbound, InboundUpdateParams, InboundQueryParams } from "../../models"; export class InboundModule extends RequestService { constructor(apiKey: string, baseUrl: string) { super(apiKey, baseUrl); } async create(inbound: Inbound) { return await this.post(`/inbound`, inbound); } async list(queryParams?: InboundQueryParams): Promise { return await this.get(`/inbound`, queryParams); } async single(inboundId: string): Promise { return await this.get(`/inbound/${inboundId}`); } async delete(inboundId: string): Promise { return await this.deleteReq(`/inbound/${inboundId}`); } async update(inboundId: string, data: InboundUpdateParams): Promise { return await this.put(`/inbound/${inboundId}`, data); } } ================================================ FILE: src/modules/email/Message.module.ts ================================================ import { RequestService, APIResponse } from "../../services/request.service"; import { MessageQueryParams } from "../../models"; export class MessageModule extends RequestService { constructor(apiKey: string, baseUrl: string) { super(apiKey, baseUrl); } async list(queryParams?: MessageQueryParams): Promise { return await this.get(`/messages`, queryParams); } async single(messageId: string): Promise { return await this.get(`/messages/${messageId}`); } } ================================================ FILE: src/modules/email/Recipient.module.ts ================================================ import { RequestService, APIResponse } from "../../services/request.service"; import { BlockListQueryParams, BlockListRecipients, BlockListRecipientsPost, BlockListType, OnHoldListQueryParams, RecipientsQueryParams } from "../../models"; const MIN_LIMIT = 10; const MAX_LIMIT = 100; export class RecipientModule extends RequestService { constructor(apiKey: string, baseUrl: string) { super(apiKey, baseUrl); } async list(queryParams?: RecipientsQueryParams): Promise { return await this.get(`/recipients`, queryParams); } async single(recipientId: string): Promise { return await this.get(`/recipients/${recipientId}`); } async delete(recipientId: string): Promise { return await this.deleteReq(`/recipients/${recipientId}`); } async blockList(queryParams?: BlockListQueryParams, type?: BlockListType.BLOCK_LIST | BlockListType.HARD_BOUNCES_LIST | BlockListType.SPAM_COMPLAINTS_LIST | BlockListType.UNSUBSCRIBES_LIST): Promise; async blockList(queryParams?: OnHoldListQueryParams, type?: BlockListType.ON_HOLD_LIST): Promise; async blockList(queryParams?: BlockListQueryParams | OnHoldListQueryParams, type: BlockListType = BlockListType.BLOCK_LIST): Promise { if (queryParams?.limit !== undefined) { if (queryParams.limit < MIN_LIMIT || queryParams.limit > MAX_LIMIT) { throw new Error(`Limit must be between ${MIN_LIMIT} and ${MAX_LIMIT}.`); } } return await this.get(`/suppressions/${type}`, queryParams); } async blockRecipients(blockRecipients: BlockListRecipients, type?: BlockListType.BLOCK_LIST): Promise; async blockRecipients(blockRecipients: BlockListRecipientsPost, type: BlockListType.HARD_BOUNCES_LIST | BlockListType.SPAM_COMPLAINTS_LIST | BlockListType.UNSUBSCRIBES_LIST): Promise; async blockRecipients(blockRecipients: BlockListRecipients | BlockListRecipientsPost, type: BlockListType = BlockListType.BLOCK_LIST): Promise { if (type === BlockListType.BLOCK_LIST) { const params = blockRecipients as BlockListRecipients; if (!params.recipients?.length && !params.patterns?.length) { throw new Error('Either recipients or patterns must be provided.'); } } else { const params = blockRecipients as BlockListRecipientsPost; if (!params.recipients.length) { throw new Error('Recipients must not be empty.'); } } return await this.post(`/suppressions/${type}`, blockRecipients); } async delBlockListRecipients(ids: string[], type: BlockListType = BlockListType.BLOCK_LIST, domainId?: string): Promise { return await this.deleteReq<{ ids: string[], domain_id?: string }>(`/suppressions/${type}`, { ids, ...(domainId && { domain_id: domainId }) }); } async delAllBlockListRecipients(type: BlockListType = BlockListType.BLOCK_LIST, domainId?: string): Promise { return await this.deleteReq<{ all: boolean, domain_id?: string }>(`/suppressions/${type}`, { all: true, ...(domainId && { domain_id: domainId }) }); } } ================================================ FILE: src/modules/email/Schedule.module.ts ================================================ import { RequestService, APIResponse } from "../../services/request.service"; import { ScheduleQueryParams } from "../../models"; export class ScheduleModule extends RequestService { constructor(apiKey: string, baseUrl: string) { super(apiKey, baseUrl); } async list(queryParams?: ScheduleQueryParams): Promise { return await this.get(`/message-schedules`, queryParams); } async single(messageId: string): Promise { return await this.get(`/message-schedules/${messageId}`); } async delete(messageId: string): Promise { return await this.deleteReq(`/message-schedules/${messageId}`); } } ================================================ FILE: src/modules/email/SmtpUser.module.ts ================================================ import { RequestService, APIResponse } from "../../services/request.service"; import { SmtpUserParams, SmtpUserQueryParams } from "../../models"; export class SmtpUserModule extends RequestService { constructor(apiKey: string, baseUrl: string) { super(apiKey, baseUrl); } async list(domainId: string, queryParams?: SmtpUserQueryParams): Promise { return await this.get(`/domains/${domainId}/smtp-users`, queryParams); } async single(domainId: string, smtpUserId: string): Promise { return await this.get(`/domains/${domainId}/smtp-users/${smtpUserId}`); } async create(domainId: string, data: SmtpUserParams): Promise { return await this.post(`/domains/${domainId}/smtp-users`, data); } async update(domainId: string, smtpUserId: string, data: Partial): Promise { return await this.put(`/domains/${domainId}/smtp-users/${smtpUserId}`, data); } async delete(domainId: string, smtpUserId: string): Promise { return await this.deleteReq(`/domains/${domainId}/smtp-users/${smtpUserId}`); } } ================================================ FILE: src/modules/email/Template.module.ts ================================================ import { RequestService, APIResponse } from "../../services/request.service"; import { TemplateQueryParams, TemplateParams, TemplateUpdateParams } from "../../models"; export class TemplateModule extends RequestService { constructor(apiKey: string, baseUrl: string) { super(apiKey, baseUrl); } async list(queryParams?: TemplateQueryParams): Promise { return await this.get(`/templates`, queryParams); } async single(templateId: string): Promise { return await this.get(`/templates/${templateId}`); } async delete(templateId: string): Promise { return await this.deleteReq(`/templates/${templateId}`); } async create(params: TemplateParams): Promise { return await this.post(`/templates`, params); } async update(templateId: string, params: TemplateUpdateParams): Promise { return await this.put(`/templates/${templateId}`, params); } } ================================================ FILE: src/modules/email/Webhook.module.ts ================================================ import { RequestService, APIResponse } from "../../services/request.service"; import { EmailWebhook, IEmailWebhookUpdateParams } from "../../models"; export class EmailWebhookModule extends RequestService { constructor(apiKey: string, baseUrl: string) { super(apiKey, baseUrl); } async create(params: EmailWebhook): Promise { return await this.post("/webhooks", params); } async list(domainId: string, queryParams?: { limit?: number; page?: number }): Promise { return await this.get("/webhooks", { domain_id: domainId, ...queryParams }); } async single(webhookId: string): Promise { return await this.get(`/webhooks/${webhookId}`); } async update(webhookId: string, updates: IEmailWebhookUpdateParams): Promise { return await this.put(`/webhooks/${webhookId}`, updates); } async delete(webhookId: string): Promise { return await this.deleteReq(`/webhooks/${webhookId}`); } } ================================================ FILE: src/modules/sms/Activity.module.ts ================================================ import { SmsActivityQueryParams } from "../../models"; import { RequestService, APIResponse } from "../../services/request.service"; export class SmsActivityModule extends RequestService { constructor(apiKey: string, baseUrl: string) { super(apiKey, baseUrl); } async list(queryParams?: SmsActivityQueryParams): Promise { return await this.get(`/sms-activity`, queryParams); } } ================================================ FILE: src/modules/sms/Inbound.module.ts ================================================ import { ActivityQueryParams, SmsInbound, SmsInboundQueryParams, SmsInboundUpdate } from "../../models"; import { RequestService, APIResponse } from "../../services/request.service"; export class SmsInboundModule extends RequestService { constructor(apiKey: string, baseUrl: string) { super(apiKey, baseUrl); } async create(smsInbound: SmsInbound) { return await this.post(`/sms-inbounds`, smsInbound); } async list(queryParams?: SmsInboundQueryParams): Promise { return await this.get(`/sms-inbounds`, queryParams); } async single(smsInboundId: string): Promise { return await this.get(`/sms-inbounds/${smsInboundId}`); } async delete(smsInboundId: string): Promise { return await this.deleteReq(`/sms-inbounds/${smsInboundId}`); } async update(smsInboundId: string, data: SmsInboundUpdate): Promise { return await this.put(`/sms-inbounds/${smsInboundId}`, data); } } ================================================ FILE: src/modules/sms/Message.module.ts ================================================ import { SmsMessageQueryParams } from "../../models"; import { RequestService, APIResponse } from "../../services/request.service"; export class SmsMessageModule extends RequestService { constructor(apiKey: string, baseUrl: string) { super(apiKey, baseUrl); } async list(queryParams?: SmsMessageQueryParams): Promise { return await this.get(`/sms-messages`, queryParams); } async single(smsMessageId: string): Promise { return await this.get(`/sms-messages/${smsMessageId}`); } } ================================================ FILE: src/modules/sms/Number.module.ts ================================================ import { SmsNumberQueryParams } from "../../models"; import { RequestService, APIResponse } from "../../services/request.service"; export class SmsNumberModule extends RequestService { constructor(apiKey: string, baseUrl: string) { super(apiKey, baseUrl); } async list(queryParams?: SmsNumberQueryParams): Promise { return await this.get(`/sms-numbers`, queryParams); } async single(smsNumberId: string): Promise { return await this.get(`/sms-numbers/${smsNumberId}`); } async update(smsNumberId: string, paused: boolean): Promise { return await this.put(`/sms-numbers/${smsNumberId}`, { paused }); } async delete(smsNumberId: string): Promise { return await this.deleteReq(`/sms-numbers/${smsNumberId}`); } } ================================================ FILE: src/modules/sms/Recipient.module.ts ================================================ import { SmsRecipientQueryParams } from "../../models"; import { RequestService, APIResponse } from "../../services/request.service"; export class SmsRecipientModule extends RequestService { constructor(apiKey: string, baseUrl: string) { super(apiKey, baseUrl); } async list(queryParams?: SmsRecipientQueryParams): Promise { return await this.get(`/sms-recipients`, queryParams); } async single(smsRecipientId: string): Promise { return await this.get(`/sms-recipients/${smsRecipientId}`); } async update(smsRecipientId: string, status: "active" | "opt_out"): Promise { return await this.put(`/sms-recipients/${smsRecipientId}`, { status }); } } ================================================ FILE: src/modules/sms/Webhook.module.ts ================================================ import { SmsWebhook, SmsWebhookQueryParams, SmsWebhookUpdate } from "../../models"; import { RequestService, APIResponse } from "../../services/request.service"; export class SmsWebhookModule extends RequestService { constructor(apiKey: string, baseUrl: string) { super(apiKey, baseUrl); } async create(params: SmsWebhook): Promise { return await this.post("/sms-webhooks", params); } async list(queryParams: SmsWebhookQueryParams): Promise { return await this.get("/sms-webhooks", queryParams); } async single(smsWebhookId: string): Promise { return await this.get(`/sms-webhooks/${smsWebhookId}`); } async update(smsWebhookId: string, data: SmsWebhookUpdate): Promise { return await this.put(`/sms-webhooks/${smsWebhookId}`, data); } async delete(smsWebhookId: string): Promise { return await this.deleteReq(`/sms-webhooks/${smsWebhookId}`); } } ================================================ FILE: src/services/mailersend.utils.ts ================================================ import { createHmac, timingSafeEqual } from "crypto"; export class MailerSendUtils { static verifyWebHook(rawBody: Buffer, signature: string, signingSecret: string): boolean { if (!signature) { throw new Error("No signature provided"); } if (!rawBody) { throw new Error("No raw body provided"); } if (!signingSecret) { throw new Error("No secret provided"); } const rawData = rawBody.toString("utf8"); const hmacSignature = createHmac("sha256", signingSecret).update(rawData, "utf8").digest("hex"); return timingSafeEqual(Buffer.from(signature), Buffer.from(hmacSignature)); } } ================================================ FILE: src/services/request.service.ts ================================================ import { request as gRequest } from "gaxios"; import { GaxiosOptions } from "gaxios"; var qs = require('qs'); export class RequestService { private readonly apiKey: string; private readonly baseUrl: string; constructor(apiKey: string, baseUrl: string) { this.apiKey = apiKey; this.baseUrl = baseUrl; } private normalizeHeaders(headers: any): Record { if (headers instanceof Headers) { return Object.fromEntries(headers.entries()); } return headers; } protected async post(path: string, data: T): Promise { return this.request("POST", path, data); } protected async get(path: string, queryParams?: any): Promise { return this.request("GET", path, null, queryParams); } protected async deleteReq(path: string, data?: T): Promise { return this.request("DELETE", path, data); } protected async put(path: string, data: any): Promise { return this.request("PUT", path, data); } private async request(method: "POST" | "GET" | "DELETE" | "PUT", path: string, body?: any, queryParams?: any) { try { const requestParams: GaxiosOptions = { url: path.replace(/^\//, ''), baseURL: this.baseUrl.endsWith('/') ? this.baseUrl : this.baseUrl + '/', method, headers: { Authorization: `Bearer ${this.apiKey}` }, responseType: "json", fetchImplementation: globalThis.fetch, } as any; if (body) { requestParams.data = body; } if (queryParams) { requestParams.params = new URLSearchParams(qs.stringify(queryParams)); } const { headers, data, status } = await gRequest(requestParams); return { headers: this.normalizeHeaders(headers), body: data, statusCode: status }; } catch (e: any) { if (e?.response) { const { headers, data, status } = e.response; throw { headers: this.normalizeHeaders(headers), body: data, statusCode: status }; } else { throw e; } } } } export interface APIResponse { headers: any; body: any; statusCode: number; } ================================================ FILE: tsconfig.json ================================================ { "compilerOptions": { "target": "ES2015", "module": "commonjs", "declaration": true, "outDir": "./lib", "strict": true, "esModuleInterop": true }, "include": [ "./src/" ], "exclude": [ "node_modules", "**/__tests__/*", "src/backup/**" ] }