1.0.1 ā€¢ Published 2 years ago

@thermopylae/lib.email v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Email client.

Install

npm install @thermopylae/lib.email

Description

This package contains EmailClient which can send emails. In order to accomplish this task, it uses internally nodemailer npm package.

Usage

import { EmailClient } from '@thermopylae/lib.email';

(async function main() {
    const emailClient = new EmailClient({
        transport: {
            options: {
                service: 'gmail',
                auth: {
                    type: 'OAuth2',
                    user: 'sample_user@gmail.com',
                    clientId: 'CLIENT-ID',
                    clientSecret: 'CLIENT-SECRET',
                    refreshToken: 'REFRESH-TOKEN',
                    accessToken: 'ACCESS-TOKEN'
                }
            },
            defaults: {
                from: 'sample_user@gmail.com'
            }
        },
        hooks: {
            onTransportError(err) {
                console.error('Error encountered in email transport: ', err);
            },
            onTransportIdle() {
                console.info('Email transport is idle.');
            }
        }
    });
    
    const sentEmailInfo = await emailClient.send({
        to: ['anoter_user@example.com'],
        subject: 'Demo Email',
        text: 'Demo text'
    });
    console.log('Email has been sent. Details: ', JSON.stringify(sentEmailInfo));
    
    emailClient.close();
})();

API Reference

API documentation is available here.

It can also be generated by issuing the following commands:

git clone git@github.com:marinrusu1997/thermopylae.git
cd thermopylae
yarn install
yarn workspace @thermopylae/lib.email run doc

Author

šŸ‘¤ Rusu Marin

šŸ“ License

Copyright Ā© 2021 Rusu Marin. This project is MIT licensed.