MailSystem.js 799 B

12345678910111213141516171819202122232425262728293031
  1. const nodemailer = require("nodemailer");
  2. const Config = require('./config');
  3. class MailSystem {
  4. constructor() {
  5. this.transporter = nodemailer.createTransport({
  6. host: Config.MAIL_HOST,
  7. port: Config.MAIL_PORT,
  8. secure: Config.MAIL_SECURE, // true for 465, false for other ports
  9. auth: Config.MAIL_AUTH,
  10. tls: {
  11. rejectUnauthorized: false
  12. }
  13. });
  14. }
  15. send(recipient, subject, text, html) {
  16. // send mail with defined transport object
  17. console.log(html)
  18. return this.transporter.sendMail({
  19. from: Config.MAIL_SENDER, // sender address
  20. to: recipient, // list of receivers
  21. subject: subject, // Subject line
  22. //text: text, // plain text body
  23. html: html // html body
  24. })
  25. //.then(console.log).catch(console.log);
  26. }
  27. }
  28. module.exports = new MailSystem();