Class which creates instances to sent emails.
config
- (Object) optional object with options of the service.isSendEmail
- (Boolean) iftrue
then we send emails using mailer servicesavedEmailHtmlPath
- (String) path to html filesmailgun
- (Object) - object with options formailgun-js
apiKey
- (String) - Your Mailgun API KEYpublicApiKey
- (String) - Your public Mailgun API KEYdomain
- (String) - Your Mailgun Domain (Please note: domain field isMY-DOMAIN-NAME.com
, nothttps://api.mailgun.net/v3/MY-DOMAIN-NAME.com
)mute
- (Boolena) - Set totrue
if you wish to mute the console error logs in validateWebhook() functionagent
- The Agent to use - see request options for the provided values. Note When providing anagent
it must be able to handle the provided (or default)protocol
.timeout
- (Number) - Request timeout in millisecondshost
- (String) - the mailgun host (default:'api.mailgun.net'
)protocol
- (String) - the mailgun protocol (default:'https:'
, possible values:'http:'
or'https:'
)port
- (String) - the mailgun port (default:'443'
)endpoint
- (String) - the mailgun host (default:'/v3'
)retry
- (Number) - the number of total attempts to do when performing requests. Default is1
. That is, we will try an operation only once with no retries on error. You can also use a config object compatible with the async library for more control as to how the retries take place. See docs here
const mailService = new MailService({
isSendEmail: false,
savedEmailHtmlPath: __dirname,
mailgun: {
apiKey: 'test',
domain: 'test.info',
},
templatesDir: __dirname,
});
Async function to send email using email template.
templateName
- (String) - name of the template in the directory that was specified in the optiontemplatesDir
templateData
- (Object) - optional object with data that need for constructing resulting htmldata
- (Object) - optional object where we specify data for sending emailsfrom
- (String) - email senderto
- (String) - receiver of the emailsubject
- (String) - subject of the email
Promise which resolve data of the mailgun.
const mailService = new MailService({
// ...
});
const result = await mailService.send(
'email.html',
{ name: 'User name' },
{
from: 'Excited User <[email protected]>',
to: '[email protected]',
subject: 'Test email',
}
);