https://github.com/mailslurp/examples
{
"name": "bun-js-send-email",
"module": "bun.spec.js",
"type": "module",
"devDependencies": {
"@types/bun": "latest"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"dependencies": {
"mailslurp-client": "^15.18.2",
"nodemailer": "^6.9.11"
}
}
{
"compilerOptions": {
// Enable latest features
"lib": ["ESNext"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,
// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,
// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,
// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}
import {test, expect } from "bun:test";
//<gen>bun_import_nodemailer
import nodemailer from "nodemailer";
//</gen>
//<gen>bun_import_mailslurp
import {MailSlurp} from "mailslurp-client";
//</gen>
test("send email", async () => {
// configure mailslurp test inbox
const apiKey = process.env.API_KEY;
if (!apiKey) {
throw new Error("Please set API_KEY environment variable")
}
//<gen>bun_create_mailserver
const mailslurp = new MailSlurp({apiKey})
const {
smtpServerHost, smtpServerPort,
smtpUsername, smtpPassword
} = await mailslurp.getImapSmtpAccessDetails();
//</gen>
// create inboxes to send and receive with
const inbox1 = await mailslurp.createInboxWithOptions({inboxType: 'SMTP_INBOX'})
const inbox2 = await mailslurp.createInboxWithOptions({inboxType: 'SMTP_INBOX'})
//<gen>bun_nodemailer_setup
const transporter = nodemailer.createTransport({
host: smtpServerHost,
port: smtpServerPort,
secure: false,
auth: {
user: smtpUsername,
pass: smtpPassword
},
});
//</gen>
//<gen>bun_send_email
const sent = await transporter.sendMail({
from: inbox1.emailAddress,
to: inbox2.emailAddress,
subject: "Test email",
text: "Hello world!",
});
//</gen>
expect(sent).toBeTruthy()
//<gen>bun_read_email
const email = await mailslurp.waitForLatestEmail(inbox2.id, 30_000, true);
expect(email.subject).toContain("Test email")
expect(email.body).toContain("Hello world!")
//</gen>
});
#!/usr/bin/env bun
bun-lockfile-format-v0
��1ͥ���<�_q��yv�3���<��\��0 � �5
�% �url qs 8 �� ��
�hasown 8
�N �E �� �� �� �B �� �gopd . �punycode� �� �2
�x
�� �tr46
�� �� �� �G �
�J+��x_���Nx��/��l���B+�~����,x�fm���
�Z���}EyB���E
�=��U(H?� �J�Л��qm����#�������%M!��?�?^�v�C����8���u��@�{���T2�?Qɸh�����S�Ĥ)>b�7]V��5�q/�;غ6�N������ŗ�8֤*ދuI)J:f�ؙ��C�)�K0��{�g͈�"�˘y�j�i�/Z�&�=9 o<��Q���%�,+�eb ? = � | J � � / � - � D @ � � E �
� B � Y 4 � � B � � >