Skip to content

Commit 380c211

Browse files
Initial commit
0 parents  commit 380c211

16 files changed

+2050
-0
lines changed

.eslintrc.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
env: {
3+
node: true,
4+
es2021: true,
5+
},
6+
extends: [
7+
"airbnb-base",
8+
"airbnb-typescript/base",
9+
"plugin:prettier/recommended",
10+
],
11+
parser: "@typescript-eslint/parser",
12+
parserOptions: {
13+
project: "tsconfig.json",
14+
},
15+
plugins: ["@typescript-eslint"],
16+
rules: {},
17+
ignorePatterns: ["dist/**", "examples/**", ".eslintrc.js"],
18+
};

.github/workflows/test.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: test
2+
3+
on: push
4+
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v2
11+
- uses: actions/setup-node@v3
12+
with:
13+
node-version: 16
14+
cache: 'yarn'
15+
- run: yarn install --frozen-lockfile
16+
- run: yarn lint

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist
2+
node_modules

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## [3.0.0] - 2022-06-14
2+
3+
- Initial release of the official mailtrap.io API client
4+
- This release is a completely new library, incompatible with v2.
5+
6+
## [2.0.2]
7+
8+
- [Simple mailtrap.io client and helper library](https://github.com/vchin/mailtrap-client) by [@vchin](https://github.com/vchin).

CODE_OF_CONDUCT.md

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6+
7+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8+
9+
## Our Standards
10+
11+
Examples of behavior that contributes to a positive environment for our community include:
12+
13+
* Demonstrating empathy and kindness toward other people
14+
* Being respectful of differing opinions, viewpoints, and experiences
15+
* Giving and gracefully accepting constructive feedback
16+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17+
* Focusing on what is best not just for us as individuals, but for the overall community
18+
19+
Examples of unacceptable behavior include:
20+
21+
* The use of sexualized language or imagery, and sexual attention or advances of any kind
22+
* Trolling, insulting or derogatory comments, and personal or political attacks
23+
* Public or private harassment
24+
* Publishing others' private information, such as a physical or email address, without their explicit permission
25+
* Other conduct which could reasonably be considered inappropriate in a professional setting
26+
27+
## Enforcement Responsibilities
28+
29+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
30+
31+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
32+
33+
## Scope
34+
35+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
36+
37+
## Enforcement
38+
39+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [email protected]. All complaints will be reviewed and investigated promptly and fairly.
40+
41+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
42+
43+
## Enforcement Guidelines
44+
45+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
46+
47+
### 1. Correction
48+
49+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
50+
51+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
52+
53+
### 2. Warning
54+
55+
**Community Impact**: A violation through a single incident or series of actions.
56+
57+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
58+
59+
### 3. Temporary Ban
60+
61+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
62+
63+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
64+
65+
### 4. Permanent Ban
66+
67+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
68+
69+
**Consequence**: A permanent ban from any sort of public interaction within the community.
70+
71+
## Attribution
72+
73+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
74+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
75+
76+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
77+
78+
[homepage]: https://www.contributor-covenant.org
79+
80+
For answers to common questions about this code of conduct, see the FAQ at
81+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.

LICENSE.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2022 Railsware Products Studio, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
![TypeScript](https://badgen.net/badge/icon/TypeScript/?icon=typescript&label) [![test](https://github.com/railsware/mailtrap-nodejs/actions/workflows/test.yml/badge.svg)](https://github.com/railsware/mailtrap-nodejs/actions/workflows/test.yml)
2+
3+
# Official Mailtrap Node.js client
4+
5+
This NPM package offers integration with the [official API](https://api-docs.mailtrap.io/) for [Mailtrap](https://mailtrap.io).
6+
7+
Quickly add email sending functionality to your Node.js application with Mailtrap.
8+
9+
## Compatibility with previous releases
10+
11+
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.
12+
13+
## Installation
14+
15+
Use yarn or npm to install the package:
16+
17+
```sh
18+
yarn add mailtrap
19+
20+
# or, if you are using NPM:
21+
npm install mailtrap
22+
```
23+
24+
## Usage
25+
26+
Refer to the [`examples`](examples) folder for the source code of these examples.
27+
28+
### Minimal
29+
30+
```js
31+
const { MailtrapClient } = require("mailtrap");
32+
33+
// For this example to work, you need to set up a sending domain,
34+
// and obtain a token that is authorized to send from the domain
35+
const TOKEN = "your-api-token";
36+
const SENDER_EMAIL = "[email protected]";
37+
const RECIPIENT_EMAIL = "[email protected]";
38+
39+
const client = new MailtrapClient({ token: TOKEN });
40+
41+
const sender = { name: "Mailtrap Test", email: SENDER_EMAIL };
42+
43+
client
44+
.send({
45+
from: sender,
46+
to: [{ email: RECIPIENT_EMAIL }],
47+
subject: "Hello from Mailtrap!",
48+
text: "Welcome to Mailtrap Sending!",
49+
})
50+
.then(console.log, console.error);
51+
```
52+
53+
### Full
54+
55+
```js
56+
const fs = require("fs");
57+
const path = require("path");
58+
const { MailtrapClient } = require("mailtrap");
59+
60+
// For this example to work, you need to set up a sending domain,
61+
// and obtain a token that is authorized to send from the domain
62+
const TOKEN = "your-api-token";
63+
const SENDER_EMAIL = "[email protected]";
64+
const RECIPIENT_EMAIL = "[email protected]";
65+
66+
const client = new MailtrapClient({ token: TOKEN });
67+
68+
const sender = { name: "Mailtrap Test", email: SENDER_EMAIL };
69+
70+
const welcomeImage = fs.readFileSync(path.join(__dirname, "welcome.png"));
71+
72+
client
73+
.send({
74+
category: "test",
75+
custom_variables: {
76+
hello: "world",
77+
year: 2022,
78+
anticipated: true,
79+
},
80+
from: sender,
81+
to: [{ email: RECIPIENT_EMAIL }],
82+
subject: "Hello from Mailtrap!",
83+
html: `
84+
<!doctype html>
85+
<html>
86+
<head>
87+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
88+
</head>
89+
<body style="font-family: sans-serif;">
90+
<div style="display: block; margin: auto; max-width: 600px;" class="main">
91+
<h1 style="font-size: 18px; font-weight: bold; margin-top: 20px">Congrats for sending test email with Mailtrap!</h1>
92+
<p>Inspect it using the tabs you see above and learn how this email can be improved.</p>
93+
<img alt="Inspect with Tabs" src="cid:welcome.png" style="width: 100%;">
94+
<p>Now send your email using our fake SMTP server and integration of your choice!</p>
95+
<p>Good luck! Hope it works.</p>
96+
</div>
97+
<!-- Example of invalid for email html/css, will be detected by Mailtrap: -->
98+
<style>
99+
.main { background-color: white; }
100+
a:hover { border-left-width: 1em; min-height: 2em; }
101+
</style>
102+
</body>
103+
</html>
104+
`,
105+
attachments: [
106+
{
107+
filename: "welcome.png",
108+
content_id: "welcome.png",
109+
disposition: "inline",
110+
content: welcomeImage,
111+
},
112+
],
113+
})
114+
.then(console.log, console.error);
115+
```
116+
117+
## Development
118+
119+
This library is developed using [TypeScript](https://www.typescriptlang.org).
120+
121+
Use `yarn lint` to perform linting with [ESLint](https://eslint.org).
122+
123+
## Contributing
124+
125+
Bug reports and pull requests are welcome on [GitHub](https://github.com/railsware/mailtrap-nodejs). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](CODE_OF_CONDUCT.md).
126+
127+
## License
128+
129+
The package is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
130+
131+
## Code of Conduct
132+
133+
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).

examples/everything.js

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
const { MailtrapClient } = require("mailtrap");
4+
5+
// For this example to work, you need to set up a sending domain,
6+
// and obtain a token that is authorized to send from the domain
7+
const TOKEN = "your-api-token";
8+
const SENDER_EMAIL = "[email protected]";
9+
const RECIPIENT_EMAIL = "[email protected]";
10+
11+
const client = new MailtrapClient({ token: TOKEN });
12+
13+
const sender = { name: "Mailtrap Test", email: SENDER_EMAIL };
14+
15+
const welcomeImage = fs.readFileSync(path.join(__dirname, "welcome.png"));
16+
17+
client
18+
.send({
19+
category: "test",
20+
custom_variables: {
21+
hello: "world",
22+
year: 2022,
23+
anticipated: true,
24+
},
25+
from: sender,
26+
to: [{ email: RECIPIENT_EMAIL }],
27+
subject: "Hello from Mailtrap!",
28+
html: `
29+
<!doctype html>
30+
<html>
31+
<head>
32+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
33+
</head>
34+
<body style="font-family: sans-serif;">
35+
<div style="display: block; margin: auto; max-width: 600px;" class="main">
36+
<h1 style="font-size: 18px; font-weight: bold; margin-top: 20px">Congrats for sending test email with Mailtrap!</h1>
37+
<p>Inspect it using the tabs you see above and learn how this email can be improved.</p>
38+
<img alt="Inspect with Tabs" src="cid:welcome.png" style="width: 100%;">
39+
<p>Now send your email using our fake SMTP server and integration of your choice!</p>
40+
<p>Good luck! Hope it works.</p>
41+
</div>
42+
<!-- Example of invalid for email html/css, will be detected by Mailtrap: -->
43+
<style>
44+
.main { background-color: white; }
45+
a:hover { border-left-width: 1em; min-height: 2em; }
46+
</style>
47+
</body>
48+
</html>
49+
`,
50+
attachments: [
51+
{
52+
filename: "welcome.png",
53+
content_id: "welcome.png",
54+
disposition: "inline",
55+
content: welcomeImage,
56+
},
57+
],
58+
})
59+
.then(console.log, console.error);

examples/minimal.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const { MailtrapClient } = require("mailtrap");
2+
3+
// For this example to work, you need to set up a sending domain,
4+
// and obtain a token that is authorized to send from the domain
5+
const TOKEN = "your-api-token";
6+
const SENDER_EMAIL = "[email protected]";
7+
const RECIPIENT_EMAIL = "[email protected]";
8+
9+
const client = new MailtrapClient({ token: TOKEN });
10+
11+
const sender = { name: "Mailtrap Test", email: SENDER_EMAIL };
12+
13+
client
14+
.send({
15+
from: sender,
16+
to: [{ email: RECIPIENT_EMAIL }],
17+
subject: "Hello from Mailtrap!",
18+
text: "Welcome to Mailtrap Sending!",
19+
})
20+
.then(console.log, console.error);

examples/welcome.png

10.1 KB
Loading

0 commit comments

Comments
 (0)