|
| 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 | +}); |
0 commit comments