-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples: init transport samples, send testing mail sample
- Loading branch information
1 parent
49e099d
commit eed53c6
Showing
3 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>"; | ||
|
||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
})) | ||
|
||
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) |