Skip to content

Commit

Permalink
function for verifying email credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
nymank committed Oct 15, 2024
1 parent 08d592f commit c653fd8
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion back/mailer.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,39 @@ const scheduleEmails = (() => {
};
})();

module.exports = { scheduleEmails, email, sendPending };

/**
* Check whether email and password match when sending SMTP
* @param emailSettings
* @returns Error object or true
*/
const verifyEmailCredentials = (emailSettings) => {
try {

const transporter = nodemailer.createTransport({
name: 'tasera.fi',
host: emailSettings.host,
port: emailSettings.port,
secure: emailSettings.secure === 'true',
auth: {
user: emailSettings.user,
pass: emailSettings.pass,
}
});

transporter.verify(function (error, success) {
if (error) {
console.log("verifyEmailCredentials failed:", error);
return false;
} else {
console.log("verifyEmailCredentials success:", success);
return true;
}
});
} catch (err) {
console.error("verifyEmailCredentials error:", err)
}

}

module.exports = { scheduleEmails, email, sendPending, verifyEmailCredentials };

0 comments on commit c653fd8

Please sign in to comment.