From 26a7201d723372dc36d8ec7ce9d6b6830448b5db Mon Sep 17 00:00:00 2001 From: moepoi Date: Tue, 16 Nov 2021 13:18:18 +0700 Subject: [PATCH] Add send Mail module --- modules/mail.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 modules/mail.js diff --git a/modules/mail.js b/modules/mail.js new file mode 100644 index 0000000..c8e968c --- /dev/null +++ b/modules/mail.js @@ -0,0 +1,43 @@ +var nodemailer = require("nodemailer"); + +let config; +try { + config = require('../config'); +} catch (e) { + console.log('No config file found'); + process.exit(0); +} + +function send(email, token) { + var email = email; + var token = token; + var mail = nodemailer.createTransport({ + host: config.mail.host, + port: config.mail.port, + secure: false, + auth: { + user: config.mail.user, + pass: config.mail.password, + }, + tls: { + rejectUnauthorized: false, + }, + }); + var mailOptions = { + from: config.mail.user, + to: email, + subject: "Account Verification - Nekoya", + html: `

Hello!!! Please click this link link to verify your account!!! Thanks!!!

` + }; + mail.sendMail(mailOptions, function (error, info) { + if (error) { + return 1; + } else { + return 0; + } + }); +} + +module.exports = { + send +} \ No newline at end of file