Skip to content
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

Restructure SDK #51

Merged
merged 31 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b96f604
types: add bulk and sandbox flags to mailtrap
narekhovhannisyan Aug 19, 2024
36a9df3
api: move testing send method to client
narekhovhannisyan Aug 19, 2024
0b49830
api: drop bulk
narekhovhannisyan Aug 19, 2024
ef8e1b9
lib: refactor MailtrapClient to incapsulate bulk, sandbox send fnality
narekhovhannisyan Aug 19, 2024
dbd5fc6
config: add bulk sandbox incompatible message
narekhovhannisyan Aug 19, 2024
e8d764b
test: drop moved functionality from Testing
narekhovhannisyan Aug 19, 2024
6f3dcd5
test: drop Bulk
narekhovhannisyan Aug 19, 2024
ce67277
test: cover new mailtrap client functionality with units
narekhovhannisyan Aug 19, 2024
e53b1c0
examples: fix mailtrap imports in testing
narekhovhannisyan Aug 19, 2024
13fc15d
examples: fix mailtrap imports in general
narekhovhannisyan Aug 19, 2024
10046b8
examples: update bulk sending example
narekhovhannisyan Aug 19, 2024
a5d4d20
docs: update Readme file, remove missing testing api notice
narekhovhannisyan Aug 19, 2024
50c8c56
types: drop sending from additional fields
narekhovhannisyan Aug 19, 2024
10f73e5
lib: drop switchable client
narekhovhannisyan Aug 19, 2024
a8b56bc
test: drop transport sandbox switch
narekhovhannisyan Aug 19, 2024
f24a304
examples: update transport sample
narekhovhannisyan Aug 19, 2024
b57bcfe
.github: configure codeql
narekhovhannisyan Aug 26, 2024
9d00310
.github: configure codeql tests path
narekhovhannisyan Aug 26, 2024
88e2acf
.github: add newline at the end of codeql config
narekhovhannisyan Aug 26, 2024
c2f1f89
.github: update codeql config to ignore all files in tests
narekhovhannisyan Aug 26, 2024
16abea3
.github: drop codeql from test workflow
narekhovhannisyan Aug 26, 2024
96d79a9
.github: tune codeql config
narekhovhannisyan Aug 26, 2024
f764542
WIP
vittorius Aug 27, 2024
7584350
.github: update codeql config path
narekhovhannisyan Aug 29, 2024
51c959c
test: drop commented code from mailtrap client
narekhovhannisyan Aug 29, 2024
7968a07
docs: move info on previous releases to the end of README
narekhovhannisyan Sep 9, 2024
49e099d
lib: separate host detection logic from send method
narekhovhannisyan Sep 9, 2024
eed53c6
examples: init transport samples, send testing mail sample
narekhovhannisyan Sep 9, 2024
b03961e
examples: fix missing comma in transport
narekhovhannisyan Sep 18, 2024
febdb9e
src: fetch changes from main
narekhovhannisyan Sep 23, 2024
9bc4687
.github: drop codeql from test workflow
narekhovhannisyan Sep 25, 2024
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
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on: push
jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ This NPM package offers integration with the [official API](https://api-docs.mai

Quickly add email sending functionality to your Node.js application with Mailtrap.

## Compatibility with previous releases

Versions of this package up to 2.0.2 were an [unofficial client](https://github.com/vchin/mailtrap-client) developed by [@vchin](https://github.com/vchin). Package version 3 is a completely new package. It is still under development and does not support the testing API yet. Please continue using version 2 if you need access to the testing API.

## Installation

Use yarn or npm to install the package:
Expand Down Expand Up @@ -125,3 +121,7 @@ The package is available as open source under the terms of the [MIT License](htt
## Code of Conduct

Everyone interacting in the Mailtrap project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).

## Compatibility with previous releases

Versions of this package up to 2.0.2 were an [unofficial client](https://github.com/vchin/mailtrap-client) developed by [@vchin](https://github.com/vchin). Package version 3 is a completely new package.
4 changes: 2 additions & 2 deletions examples/bulk/send-mail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const TOKEN = "<YOUR-TOKEN-HERE>";
const SENDER_EMAIL = "<SENDER@YOURDOMAIN.COM>";
const RECIPIENT_EMAIL = "<RECIPIENT@EMAIL.COM>";

const client = new MailtrapClient({ token: TOKEN });
const client = new MailtrapClient({ token: TOKEN, bulk: true });
narekhovhannisyan marked this conversation as resolved.
Show resolved Hide resolved

client.bulk.send({
client.send({
from: { name: "Mailtrap Test", email: SENDER_EMAIL },
to: [{ email: RECIPIENT_EMAIL }],
subject: "Hello from Mailtrap!",
Expand Down
60 changes: 60 additions & 0 deletions examples/bulk/transport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { readFileSync } from "fs";
import Nodemailer from "nodemailer";
import { MailtrapTransport } 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 = "<SENDER@YOURDOMAIN.COM>";
const RECIPIENT_EMAIL = "<RECIPIENT@EMAIL.COM>";
leonid-shevtsov marked this conversation as resolved.
Show resolved Hide resolved

const transport = Nodemailer.createTransport(MailtrapTransport({
token: TOKEN,
bulk: true
}))

transport.sendMail({
text: "Welcome to Mailtrap Sending!",
to: {
address: RECIPIENT_EMAIL,
name: "John Doe"
},
from: {
address: SENDER_EMAIL,
name: "Mailtrap Test"
},
subject: "Hello from Mailtrap!",
html: `
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body style="font-family: sans-serif;">
<div style="display: block; margin: auto; max-width: 600px;" class="main">
<h1 style="font-size: 18px; font-weight: bold; margin-top: 20px">Congrats for sending test email with Mailtrap!</h1>
<p>Inspect it using the tabs you see above and learn how this email can be improved.</p>
<img alt="Inspect with Tabs" src="cid:welcome.png" style="width: 100%;">
<p>Now send your email using our fake SMTP server and integration of your choice!</p>
<p>Good luck! Hope it works.</p>
</div>
<!-- Example of invalid for email html/css, will be detected by Mailtrap: -->
<style>
.main { background-color: white; }
a:hover { border-left-width: 1em; min-height: 2em; }
</style>
</body>
</html>
`,
attachments: [
{
filename: "welcome.png",
content: readFileSync("./welcome.png"),
},
],
}).then(console.log)
.catch(console.error)
2 changes: 1 addition & 1 deletion examples/general/account-accesses.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MailtrapClient } from "../../src"
import { MailtrapClient } from "mailtrap"

const TOKEN = "<YOUR-TOKEN-HERE>";
const TEST_INBOX_ID = "<YOUR-TEST-INBOX-ID-HERE>"
Expand Down
2 changes: 1 addition & 1 deletion examples/general/accounts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MailtrapClient } from "../../src"
import { MailtrapClient } from "mailtrap"

const TOKEN = "<YOUR-TOKEN-HERE>";
const TEST_INBOX_ID = "<YOUR-TEST-INBOX-ID-HERE>"
Expand Down
2 changes: 1 addition & 1 deletion examples/general/permissions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MailtrapClient } from "../../src"
import { MailtrapClient } from "mailtrap"

const TOKEN = "<YOUR-TOKEN-HERE>";
const TEST_INBOX_ID = "<YOUR-TEST-INBOX-ID-HERE>"
Expand Down
3 changes: 1 addition & 2 deletions examples/sending/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ const SENDER_EMAIL = "<SENDER@YOURDOMAIN.COM>";
const RECIPIENT_EMAIL = "<RECIPIENT@EMAIL.COM>";

const transport = Nodemailer.createTransport(MailtrapTransport({
token: TOKEN
token: TOKEN,
}))

// Note: 'sandbox: true' can be passed for making requests to Testing API
transport.sendMail({
text: "Welcome to Mailtrap Sending!",
to: {
Expand Down
2 changes: 1 addition & 1 deletion examples/testing/attachments.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MailtrapClient } from "../../src"
import { MailtrapClient } from "mailtrap"

const TOKEN = "<YOUR-TOKEN-HERE>";
const TEST_INBOX_ID = "<YOUR-TEST-INBOX-ID-HERE>"
Expand Down
2 changes: 1 addition & 1 deletion examples/testing/inboxes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MailtrapClient } from "../../src"
import { MailtrapClient } from "mailtrap"

const TOKEN = "<YOUR-TOKEN-HERE>";
const TEST_INBOX_ID = "<YOUR-TEST-INBOX-ID-HERE>"
Expand Down
2 changes: 1 addition & 1 deletion examples/testing/messages.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MailtrapClient } from "../../src"
import { MailtrapClient } from "mailtrap"

const TOKEN = "<YOUR-TOKEN-HERE>";
const TEST_INBOX_ID = "<YOUR-TEST-INBOX-ID-HERE>"
Expand Down
25 changes: 25 additions & 0 deletions examples/testing/send-mail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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"

const TOKEN = "<YOUR-TOKEN-HERE>";
const TEST_INBOX_ID = "<YOUR-TEST-INBOX-ID-HERE>"
const SENDER_EMAIL = "<SENDER@YOURDOMAIN.COM>";
const RECIPIENT_EMAIL = "<RECIPIENT@EMAIL.COM>";

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

client.send({
from: { name: "Mailtrap Test", email: SENDER_EMAIL },
to: [{ email: RECIPIENT_EMAIL }],
subject: "Hello from Mailtrap!",
text: "Welcome to Mailtrap Sending!",
})
.then(console.log)
.catch(console.error);
2 changes: 1 addition & 1 deletion examples/testing/template.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MailtrapClient } from "../../src"
import { MailtrapClient } from "mailtrap"

/**
* For this example to work, you need to set up a sending domain,
Expand Down
62 changes: 62 additions & 0 deletions examples/testing/transport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { readFileSync } from "fs";
import Nodemailer from "nodemailer";
import { MailtrapTransport } 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 = "<SENDER@YOURDOMAIN.COM>";
const RECIPIENT_EMAIL = "<RECIPIENT@EMAIL.COM>";

const transport = Nodemailer.createTransport(MailtrapTransport({
token: TOKEN,
testInboxId: TEST_INBOX_ID,
sandbox: true
narekhovhannisyan marked this conversation as resolved.
Show resolved Hide resolved
}))

transport.sendMail({
text: "Welcome to Mailtrap Sending!",
to: {
address: RECIPIENT_EMAIL,
name: "John Doe"
},
from: {
address: SENDER_EMAIL,
name: "Mailtrap Test"
},
subject: "Hello from Mailtrap!",
html: `
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body style="font-family: sans-serif;">
<div style="display: block; margin: auto; max-width: 600px;" class="main">
<h1 style="font-size: 18px; font-weight: bold; margin-top: 20px">Congrats for sending test email with Mailtrap!</h1>
<p>Inspect it using the tabs you see above and learn how this email can be improved.</p>
<img alt="Inspect with Tabs" src="cid:welcome.png" style="width: 100%;">
<p>Now send your email using our fake SMTP server and integration of your choice!</p>
<p>Good luck! Hope it works.</p>
</div>
<!-- Example of invalid for email html/css, will be detected by Mailtrap: -->
<style>
.main { background-color: white; }
a:hover { border-left-width: 1em; min-height: 2em; }
</style>
</body>
</html>
`,
attachments: [
{
filename: "welcome.png",
content: readFileSync("./welcome.png"),
},
],
}).then(console.log)
.catch(console.error)
146 changes: 0 additions & 146 deletions src/__tests__/lib/api/Bulk.test.ts

This file was deleted.

Loading
Loading