Skip to content

Commit b697ca0

Browse files
add-nodejs
1 parent aa8710d commit b697ca0

File tree

6 files changed

+316
-0
lines changed

6 files changed

+316
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.env
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-include ../.env
2+
3+
node_modules:
4+
npm install
5+
6+
clean:
7+
rm -rf artifacts
8+
9+
fmt:
10+
npm run fmt
11+
12+
test: node_modules
13+
API_KEY=$(API_KEY) npm t

nodejs-nodemailer-smtp-example/package-lock.json

Lines changed: 226 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "nodejs-nodemailer-smtp-example",
3+
"version": "1.0.0",
4+
"description": "NodeMailer SMTP test",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "jasmine"
8+
},
9+
"author": "mailslurp",
10+
"license": "MIT",
11+
"dependencies": {
12+
"isomorphic-fetch": "^3.0.0",
13+
"jasmine": "^4.0.2",
14+
"mailslurp-client": "^15.4.4",
15+
"nodemailer": "^6.7.2"
16+
}
17+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const MailSlurp = require("mailslurp-client").MailSlurp;
2+
const fetchApi = require("isomorphic-fetch");
3+
const nodemailer = require("nodemailer");
4+
5+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
6+
7+
describe("testing smtp", function () {
8+
it("can create an mailbox and get email preview urls", async function () {
9+
const apiKey = process.env.API_KEY;
10+
if (!apiKey) {
11+
throw new Error("Please set API_KEY environment variable")
12+
}
13+
const mailslurp = new MailSlurp({apiKey, fetchApi})
14+
const access = await mailslurp.getImapSmtpAccessDetails();
15+
expect(access).toBeTruthy();
16+
17+
const inbox1 = await mailslurp.createInboxWithOptions({inboxType: 'SMTP_INBOX'})
18+
const inbox2 = await mailslurp.createInboxWithOptions({inboxType: 'SMTP_INBOX'})
19+
20+
const transporter = nodemailer.createTransport({
21+
host: access.smtpServerHost,
22+
port: access.smtpServerPort,
23+
secure: false,
24+
auth: {
25+
user: access.smtpUsername,
26+
pass: access.smtpPassword
27+
},
28+
});
29+
30+
const sent = await transporter.sendMail({
31+
from: inbox1.emailAddress,
32+
to: inbox2.emailAddress,
33+
subject: "From inbox 1 to inbox 2",
34+
text: "Hi there"
35+
});
36+
expect(sent).toBeTruthy()
37+
38+
const email = await mailslurp.waitForLatestEmail(inbox2.id, 30_000, true);
39+
const accessUrls = await mailslurp.emailController.getEmailPreviewURLs({emailId: email.id})
40+
41+
// access these urls in browser to view email content
42+
expect(accessUrls.plainHtmlBodyUrl).toContain("https://api.mailslurp.com")
43+
expect(accessUrls.rawSmtpMessageUrl).toContain("https://api.mailslurp.com")
44+
});
45+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"spec_dir": "spec",
3+
"spec_files": [
4+
"**/*[sS]pec.?(m)js"
5+
],
6+
"helpers": [
7+
"helpers/**/*.?(m)js"
8+
],
9+
"env": {
10+
"stopSpecOnExpectationFailure": false,
11+
"random": true
12+
}
13+
}

0 commit comments

Comments
 (0)