Class which creates instances to sent emails.
config- (Object) optional object with options of the service.isSendEmail- (Boolean) iftruethen we send emails using mailer servicesavedEmailHtmlPath- (String) path to html filesmailgun- (Object) - object with options formailgun-jsapiKey- (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 totrueif you wish to mute the console error logs in validateWebhook() functionproxy- (String) - The proxy URI in formathttp[s]://[auth@]host:port. ex:'http://proxy.example.com:8080'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 optiontemplatesDirtemplateData- (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 <me@samples.mailgun.org>',
to: 'test@test.com',
subject: 'Test email',
}
);