mailslurp-examples - bun-js-send-email

https://github.com/mailslurp/examples

Table of Contents

bun-js-send-email/package.json

{
  "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"
  }
}

bun-js-send-email/jsconfig.json

{
  "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
  }
}

bun-js-send-email/bun.spec.js

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>
});

bun-js-send-email/bun.lockb

#!/usr/bin/env bun
bun-lockfile-format-v0
��1ͥ���<�_q��yv�3���<��\��0 �  �5
�%�urlqs8����
�hasown8
�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�Y4��B��>�
:�G:��:��N�ZX��L��0�.P�~8��>��>�<<��<��L�0�L5��;��4�

:�SA��<�	
 !"%%%&(***+-.//	
 !"%%%&(***+-.//����R $�!�ox�_�l���tz�Þ]/�CD���N�A[2%�AS�}�I�↓?
�e.�2\u|���Z������P�@_�^L�	�r��ܨ0���9���N#L�N���d:�[*��V���Y�YN��P�����N,g�$
�ȣ���%:�9p$������1��f�<5ՙq��+]<%���T����y�
4�׷RG���3H�m�0�ĻU7��W�+����iJ�I�=V��m+M=ͺ����~�0l+�x��G�X{�����|5�������F�x����[��=2��3o��`:9�C�������#�xڒyZ�LFE렔���#�"(�,#KWP����K3�;'��d��f��p�슝`�_8֎��-��u�l1H�A5��������!���T�S��,��rX�:#�`,L�'gN��p?|!J�1sؒ�A�U����rJE����a���	��{[��[�/���¥[�E��\��L�
l!�k�i�6�#����� $��$�L�����	�q��~�_�F�b0�Hn�:1��5à�V��v�
��a���є��!i
���S��8�H�i�1�H��
�r¸^��3pL2�u���#��Q=� ��i�>U�`|,�+(��`PRns�%�L*؏;�fy��d����H�Z��	R&R��lT���l���A�GE����	�P��O*�~@#.x�&�m���d��Q=��qq�U���e�Gجm�ӽ�o?fV,B���&32%ʜ���`��=[-m/��0	QE�Ѕ�e�ST-.����
t�5&	�p~�g�6�Z)F���ݛ-%��+�����,�T��5���
�#�wA��\�HKB������zq�>V°`{(�A%s��f����'D��fղ����Aw���m�X�8�{�瀷I��������M*����)�A���3f�/	>�1��O�p��$��B����R�陛���}�K�o.b��`�����,���J�̝�dV�@ͻ	��O~~�(��ؒ�^�����
,���������_
�����w�[6Rw�o�6i�]���W����ggU���5��|��G�1��ի_�����Oc$s1i��)6a����/#9i���f�>�p����I�"��ņi(���ӗT�,���1��̟r7e�w_�l������f
U���M]�
4��(��'(ݵvs;�;0�t�Ue��&�Q��;�${c|�]�}��������ǗZ��/��q�m�o�8�K�"M����_L����S6�vl7�����t�����5���V$����r�>'hSE������R��c/v9���GJ-��ҩ���H����?��%�g��L�C�	jNO9�S:*��s�Q}I�u�g�>�j�����ݛ
9��R��֥k"�	������["�ׯx��2���D��2������9�{��N��v7���Ҳ��E��d� .��B���
MA�.d���)o�'����.��O��ؐ'�?G��+Ħ��Hm�������(��0����^��^��ņ�h�����LZy��7u����S�@�\�ď	h�{���&	�������ֹ �Wc<�Xw���WW_��5|y��g`����f�x�`1�@VT����{.���3
��Pj��&w[�o؀C:V2���b����G�Y>�dg?/R�H��g�59��@���Hg<ޜ�-�o���Q���g�9�<j��X]���~4���/�Qk�����<L�����dQ�ږ�*�j����U��ሦ�p�r�2�KV�#���Q�9U�W�!���[���=�{����+6�����!)B��h�B^�\��V��D��
q�M�"�WL��I�_�юXt1/�վ/�h���&P�;�tB
�Qq��V�Vh3��;�?��vt�7��!�P�N�$/���Yy\/�|��!��Kf�z����u���L��@K�M��]�ʩ�;MxgN�R�~�[ع���e����ґu�Wq\�d�2y��'[h | 
<src.install.lockfile.Tree> 20 sizeof, 4 alignof
��������� $!
<u32> 4 sizeof, 4 alignof
*+,%.&	()

P!"
<u32> 4 sizeof, 4 alignof

	
			����@"'
<[26]u8> 26 sizeof, 1 alignof

��%�,+�eb^5.0.0
��)�K0��latest%���l���B+5
����Nx��/���;غ6�N^3.1.5��V��5�q/^4.2.8url�~����,^0.11.0punycode)>b�7]^1.4.1qsx�fm���^6.11.28�
�Z���}^1.0.4�	�?^�v�C��^1.0.7�	�%M!��?�^1.3.0�
��=��U(^1.2.4��EyB���E
^1.13.1�	�%M!��?�^1.3.08
����qm�^1.1.2E	������^1.0.1N����#��^1.0.3hasownH?�	�J��^2.0.08
����qm�^1.1.2���{���T2^1.0.0�	�%M!��?�^1.3.08
����qm�^1.1.2�
��=��U(^1.2.4��𷈐��8^1.2.1.����S�Ĥ^1.1.2�	�%M!��?�^1.3.08
����qm�^1.1.2�
��=��U(^1.2.3gopd�?Qɸh��^1.0.1B����u��@^1.0.1���{���T2^1.0.0�
��=��U(^1.2.4�
��=��U(^1.1.3���{���T2^1.0.0�	�%M!��?�^1.3.0gopd�?Qɸh��^1.0.12
�������^2.6.12x
�ŗ�8�^5.0.0encoding���T����^0.1.0tr46:f�ؙ��C~0.0.3���*ދuI)J^3.0.0�	�{�g͈�"1.0.29���/Z�&�=9~20.11.3�	��˘y�j�i~8.5.10���/Z�&�=9*G�	o<��Q��~5.26.4P'�'
<src.install.semver.ExternalString> 16 sizeof, 8 alignof
tsc���r��bin/tscޣ<�q�tsserver]� �RfK����85�x��'�0
<u8> 1 sizeof, 1 alignof
bun-js-send-emailtypescript@types/bunmailslurp-clientnodemailerhttps://registry.npmjs.org/nodemailer/-/nodemailer-6.9.11.tgzhttps://registry.npmjs.org/mailslurp-client/-/mailslurp-client-15.18.2.tgzcross-fetches6-promisehttps://registry.npmjs.org/url/-/url-0.11.3.tgzhttps://registry.npmjs.org/qs/-/qs-6.11.2.tgzside-channelhttps://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgzcall-bindes-errorsget-intrinsicobject-inspecthttps://registry.npmjs.org/object-inspect/-/object-inspect-1.13.1.tgzhttps://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgzfunction-bindhas-protohas-symbolshttps://registry.npmjs.org/hasown/-/hasown-2.0.1.tgzhttps://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgzhttps://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgzhttps://registry.npmjs.org/has-proto/-/has-proto-1.0.3.tgzhttps://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgzhttps://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgzes-define-propertyset-function-lengthhttps://registry.npmjs.org/set-function-length/-/set-function-length-1.2.1.tgzdefine-data-propertyhas-property-descriptorshttps://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgzhttps://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgzhttps://registry.npmjs.org/gopd/-/gopd-1.0.1.tgzhttps://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgzhttps://registry.npmjs.org/punycode/-/punycode-1.4.1.tgzhttps://registry.npmjs.org/es6-promise/-/es6-promise-4.2.8.tgzhttps://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.8.tgznode-fetchhttps://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgzwhatwg-urlhttps://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgzwebidl-conversionshttps://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgzhttps://registry.npmjs.org/tr46/-/tr46-0.0.3.tgzhttps://registry.npmjs.org/@types/bun/-/bun-1.0.8.tgzbun-typeshttps://registry.npmjs.org/bun-types/-/bun-types-1.0.29.tgz@types/node@types/wshttps://registry.npmjs.org/@types/ws/-/ws-8.5.10.tgzhttps://registry.npmjs.org/@types/node/-/node-20.11.24.tgzundici-typeshttps://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgzbin/tsserverhttps://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz

bun-js-send-email/README.md

# bun-js-send-email

To install dependencies:

```bash
bun install
```

To run:

```bash
bun run bun.spec.js
```

This project was created using `bun init` in bun v1.0.30. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.

bun-js-send-email/Makefile

-include ../.env

node_modules:
	bun install

clean:
	rm -rf artifacts

fmt:
	bun fmt

test: node_modules
	#<gen>bun_run_test
	API_KEY=$(API_KEY) bun test --timeout 60000
	#</gen>