Skip to content

Commit

Permalink
docs: update README.md file and include general and testing APIs.
Browse files Browse the repository at this point in the history
  • Loading branch information
narekhovhannisyan committed Dec 24, 2023
1 parent 9ba58b5 commit 845e7ac
Showing 1 changed file with 10 additions and 95 deletions.
105 changes: 10 additions & 95 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ npm install mailtrap

## Usage

Refer to the [`examples`](examples) folder for the source code of these examples.

### Minimal

```ts
Expand Down Expand Up @@ -54,103 +52,20 @@ client
.catch(console.error);
```

### Full

```ts
import fs from "node:fs"
import path from "node:path"

import { MailtrapClient } from "mailtrap"

/**
* For this example to work, you need to set up a sending domain,
* and obtain a token that is authorized to send from the domain.
*/

const TOKEN = "<YOUR-TOKEN-HERE>";
const SENDER_EMAIL = "<SENDER@YOURDOMAIN.COM>";
const RECIPIENT_EMAIL = "<RECIPIENT@EMAIL.COM>";
Refer to the [`examples`](examples) folder for the source code of this and other advanced examples.

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

const sender = { name: "Mailtrap Test", email: SENDER_EMAIL };
- [List User & Invite account accesses](examples/general/account-accesses.ts)
- [Remove account access](examples/general/accounts.ts)
- [Permissions](examples/general/permissions.ts)

const welcomeImage = fs.readFileSync(path.join(__dirname, "welcome.png"));
### Email testing API

client
.send({
category: "test",
custom_variables: {
hello: "world",
year: 2022,
anticipated: true,
},
from: sender,
to: [{ email: RECIPIENT_EMAIL }],
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_id: "welcome.png",
disposition: "inline",
content: welcomeImage,
},
],
})
.then(console.log)
.catch(console.error)
```

### Mail from template

```ts
import { MailtrapClient } from "mailtrap"

/**
* For this example to work, you need to set up a sending domain,
* and obtain a token that is authorized to send from the domain.
*/

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

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

client
.send({
from: { name: "Mailtrap Test", email: SENDER_EMAIL },
to: [{ email: RECIPIENT_EMAIL }],
template_uuid: "813e39db-c74a-4830-b037-0e6ba8b1fe88",
template_variables: {
user_name: "John Doe",
},
})
.then(console.log)
.catch(console.error);
```
- [Attachments](examples/testing/attachments.ts)
- [Inboxes](examples/testing/inboxes.ts)
- [Messages](examples/testing/messages.ts)
- [Projects](examples/testing/projects.ts)

### Nodemailer Transport

Expand Down

0 comments on commit 845e7ac

Please sign in to comment.