Email client.
npm install @thermopylae/lib.email
This package contains EmailClient which can send emails.
In order to accomplish this task, it uses internally nodemailer npm package.
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 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
👤 Rusu Marin
Copyright © 2021 Rusu Marin.
This project is MIT licensed.