2017-06-26 18:48:28 +02:00
|
|
|
/**
|
|
|
|
* Mail service wrapping around mailgun
|
|
|
|
*/
|
|
|
|
|
|
|
|
import nodemailer from 'nodemailer';
|
2020-09-07 13:59:15 +02:00
|
|
|
// import mg from 'nodemailer-mailgun-transport';
|
2017-06-26 18:48:28 +02:00
|
|
|
|
|
|
|
const auth = {
|
|
|
|
api_key: process.env.MAILGUN_KEY,
|
|
|
|
domain: process.env.MAILGUN_DOMAIN,
|
|
|
|
};
|
|
|
|
|
|
|
|
class Mail {
|
|
|
|
constructor() {
|
2020-09-07 13:59:15 +02:00
|
|
|
this.client = nodemailer.createTransport({
|
|
|
|
streamTransport: true,
|
|
|
|
// newline: 'windows'
|
|
|
|
});
|
2017-06-26 18:48:28 +02:00
|
|
|
this.sendOptions = {
|
|
|
|
from: process.env.EMAIL_SENDER,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
sendMail(mailOptions) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
this.client.sendMail(mailOptions, (err, info) => {
|
|
|
|
resolve(err, info);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatchMail(data, callback) {
|
|
|
|
const mailOptions = {
|
|
|
|
to: data.to,
|
|
|
|
subject: data.subject,
|
|
|
|
from: this.sendOptions.from,
|
|
|
|
html: data.html,
|
|
|
|
};
|
|
|
|
|
|
|
|
return this.sendMail(mailOptions)
|
|
|
|
.then((err, res) => {
|
|
|
|
callback(err, res);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
send(data, callback) {
|
|
|
|
return this.dispatchMail(data, callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default new Mail();
|