1.0.1 ā¢ Published 2 years ago
@thermopylae/lib.email v1.0.1
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
- GitHub: @marinrusu1997
- Email: dimarusu2000@gmail.com
- LinkedIn: @marinrusu1997
š License
Copyright Ā© 2021 Rusu Marin. This project is MIT licensed.