Skip to content

Batch Sending Api #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b38e2a6
types: add BatchMail and BatchSendResponse types to mailtrap
narekhovhannisyan May 10, 2025
927d95e
feat: implement batchSend method for sending multiple emails
narekhovhannisyan May 10, 2025
2cc5795
feat: add BATCH_ENDPOINT to client settings for batch email sending
narekhovhannisyan May 10, 2025
62df618
test: add unit test for batch email sending functionality in Mailtrap…
narekhovhannisyan May 10, 2025
f88e2ca
feat: add example for batch email sending using MailtrapClient
narekhovhannisyan May 10, 2025
268a293
docs: update README to include batch sending API example
narekhovhannisyan May 10, 2025
ec88054
feat: add bulk email sending example using MailtrapClient
narekhovhannisyan May 17, 2025
0240468
examples: create sandbox example for batch email sending with Mailtra…
narekhovhannisyan May 17, 2025
ebb20da
fix: add missing newline at end of file in bulk email sending example
narekhovhannisyan May 17, 2025
563f4fa
revert: remove deprecated batch email sending example from examples d…
narekhovhannisyan May 17, 2025
2980312
examples: add new batch email sending template example using Mailtrap…
narekhovhannisyan May 17, 2025
2a873f1
examples: add new transactional email sending example using MailtrapC…
narekhovhannisyan May 17, 2025
87c868b
fix: update documentation link in send-mail example for clarity
narekhovhannisyan May 17, 2025
0b39bab
chore: remove deprecated BATCH_ENDPOINT from configuration
narekhovhannisyan May 17, 2025
7fbe71a
refactor: change encodeMailBuffers function to accept Partial<Mail> type
narekhovhannisyan May 17, 2025
22db43b
refactor: update batchSend method to accept BatchSendRequest and rest…
narekhovhannisyan May 17, 2025
5802797
types: add BatchSendRequest and BatchSendRequestItem types for batch …
narekhovhannisyan May 17, 2025
4c78bad
test: enhance batch email sending tests with various scenarios and er…
narekhovhannisyan May 17, 2025
d5a6c1b
docs: update README to include new examples for sending transactional…
narekhovhannisyan May 17, 2025
3550280
types: refactor BatchSendRequest to use BaseAddress and separate inli…
narekhovhannisyan May 17, 2025
dea8728
test: add error handling test for incompatible bulk and sandbox modes…
narekhovhannisyan May 17, 2025
efce27f
test: remove redundant batch email sending test case
narekhovhannisyan May 17, 2025
6494340
types: add custom_variables field to BatchSendRequest for enhanced fl…
narekhovhannisyan May 17, 2025
e5b087a
docs: update batch sample references
narekhovhannisyan May 20, 2025
3a42d59
examples: remove redundant newline
narekhovhannisyan May 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ Refer to the [`examples`](examples) folder for the source code of this and other
- [Send email using template](examples/sending/template.ts)
- [Nodemailer transport](examples/sending/transport.ts)

### Batch Sending API

- [Send a batch of transactional emails](examples/batch/transactional.ts)
- [Send a batch of bulk emails](examples/batch/bulk.ts)
- [Send a batch of sandbox emails](examples/batch/sandbox.ts)
- [Send a batch of emails from template](examples/batch/template.ts)

### Email testing API

- [Attachments](examples/testing/attachments.ts)
Expand Down
39 changes: 39 additions & 0 deletions examples/batch/bulk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { MailtrapClient } from "mailtrap";

/**
* For this example, you need to have ready-to-use sending domain or,
* a Demo domain that allows sending emails to your own account email.
* @see https://help.mailtrap.io/article/69-sending-domain-setup
*/

const TOKEN = "<YOUR-TOKEN-HERE>";
const SENDER_EMAIL = "<[email protected]>";
const RECIPIENT_EMAIL = "<[email protected]>";

const client = new MailtrapClient({
token: TOKEN,
});

client.batchSend({
base: {
from: { name: "Mailtrap Test", email: SENDER_EMAIL },
subject: "Sandbox Email",
text: "Welcome to Mailtrap Sandbox Batch Sending!"
},
requests: [
{
to: [{ email: RECIPIENT_EMAIL }],
custom_variables: {
email_number: 1
}
},
{
to: [{ email: RECIPIENT_EMAIL }],
custom_variables: {
email_number: 2
}
}
]
})
.then(console.log)
.catch(console.error);
42 changes: 42 additions & 0 deletions examples/batch/sandbox.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { MailtrapClient } from "mailtrap";

/**
* For this example, you need to have ready-to-use sending domain or,
* a Demo domain that allows sending emails to your own account email.
* @see https://help.mailtrap.io/article/69-sending-domain-setup
*/

const TOKEN = "<YOUR-TOKEN-HERE>";
const TEST_INBOX_ID = "<YOUR-TEST-INBOX-ID-HERE>";
const SENDER_EMAIL = "<[email protected]>";
const RECIPIENT_EMAIL = "<[email protected]>";

const client = new MailtrapClient({
token: TOKEN,
sandbox: true,
testInboxId: TEST_INBOX_ID
});

client.batchSend({
base: {
from: { name: "Mailtrap Test", email: SENDER_EMAIL },
subject: "Sandbox Email",
text: "Welcome to Mailtrap Sandbox Batch Sending!"
},
requests: [
{
to: [{ email: RECIPIENT_EMAIL }],
custom_variables: {
email_number: 1
}
},
{
to: [{ email: RECIPIENT_EMAIL }],
custom_variables: {
email_number: 2
}
}
]
})
.then(console.log)
.catch(console.error);
39 changes: 39 additions & 0 deletions examples/batch/template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { MailtrapClient } from "mailtrap";

/**
* For this example, you need to have ready-to-use sending domain or,
* a Demo domain that allows sending emails to your own account email.
* @see https://help.mailtrap.io/article/69-sending-domain-setup
*/

const TOKEN = "<YOUR-TOKEN-HERE>";
const SENDER_EMAIL = "<[email protected]>";
const RECIPIENT_EMAIL = "<[email protected]>";
const TEMPLATE_UUID = "<TEMPLATE-UUID>";

const client = new MailtrapClient({ token: TOKEN });

client.batchSend({
base: {
from: { name: "Mailtrap Test", email: SENDER_EMAIL },
template_uuid: TEMPLATE_UUID
},
requests: [
{
to: [{ email: RECIPIENT_EMAIL }],
template_variables: {
user_name: "John Doe",
company_name: "Example Corp"
}
},
{
to: [{ email: RECIPIENT_EMAIL }],
template_variables: {
user_name: "Jane Smith",
company_name: "Example Corp"
}
}
]
})
.then(console.log)
.catch(console.error);
37 changes: 37 additions & 0 deletions examples/batch/transactional.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { MailtrapClient } from "mailtrap";

/**
* For this example, you need to have ready-to-use sending domain or,
* a Demo domain that allows sending emails to your own account email.
* @see https://help.mailtrap.io/article/69-sending-domain-setup
*/

const TOKEN = "<YOUR-TOKEN-HERE>";
const SENDER_EMAIL = "<[email protected]>";
const RECIPIENT_EMAIL = "<[email protected]>";

const client = new MailtrapClient({ token: TOKEN });

client.batchSend({
base: {
from: { name: "Mailtrap Test", email: SENDER_EMAIL },
subject: "Transactional Email",
text: "Welcome to Mailtrap Batch Sending!"
},
requests: [
{
to: [{ email: RECIPIENT_EMAIL }],
custom_variables: {
email_number: 1
}
},
{
to: [{ email: RECIPIENT_EMAIL }],
custom_variables: {
email_number: 2
}
}
]
})
.then(console.log)
.catch(console.error);
2 changes: 1 addition & 1 deletion examples/testing/send-mail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { MailtrapClient } from "mailtrap"
* For this example, you need to have ready-to-use sending domain or,
* a Demo domain that allows sending emails to your own account email.
* @see https://help.mailtrap.io/article/69-sending-domain-setup
* @see https://help.mailtrap.io/article/69-sending-domain-setup#Demo-Domain--oYOU5"
*/

", @see https://help.mailtrap.io/article/69-sending-domain-setup#Demo-Domain--oYOU5"

const TOKEN = "<YOUR-TOKEN-HERE>";
const TEST_INBOX_ID = "<YOUR-TEST-INBOX-ID-HERE>"
Expand Down
Loading