remove double message.
rate limit emails during testing
This commit is contained in:
@ -24,7 +24,11 @@ if (process.env.EMAIL_SERVICE.toLowerCase() === "mailtrap") {
|
||||
auth: {
|
||||
user: process.env.MAILTRAP_USER,
|
||||
pass: process.env.MAILTRAP_PASS
|
||||
}
|
||||
},
|
||||
pool: true, // use pooled connection
|
||||
rateLimit: true, // enable to make sure we are limiting
|
||||
maxConnections: 1, // set limit to 1 connection only
|
||||
maxMessages: 2 // send 2 emails per second
|
||||
});
|
||||
}
|
||||
else if (process.env.EMAIL_SERVICE.toLowerCase() === "gmail") {
|
||||
@ -70,16 +74,19 @@ function normalizeEmailAddresses(to) {
|
||||
|
||||
return emails; // Always returns an array
|
||||
}
|
||||
/// <summary>
|
||||
/// Final email sending function.
|
||||
/// </summary>
|
||||
/// <param name="to">Email address or array of email addresses</param>
|
||||
/// <param name="subject">Email subject</param>
|
||||
/// <param name="text">Plain text version of the email</param>
|
||||
/// <param name="html">HTML version of the email</param>
|
||||
/// <param name="attachments">Array of attachment objects</param>
|
||||
/// <returns>Promise</returns>
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Final email sending function.
|
||||
*
|
||||
* @param {string|string[]} to - Email address or array of email addresses.
|
||||
* @param {string} subject - Email subject.
|
||||
* @param {string} text - Plain text version of the email.
|
||||
* @param {string} html - HTML version of the email.
|
||||
* @param {Object[]} [attachments=[]] - Array of attachment objects.
|
||||
* @returns {Promise} - A promise that resolves when the email is sent.
|
||||
*/
|
||||
exports.SendEmail = async function (to, subject, text, html, attachments = []) {
|
||||
let sender = process.env.EMAIL_SENDER || '"Специално Свидетелстване София" <sofia@mwitnessing.com>';
|
||||
let emailAddresses = normalizeEmailAddresses(to)
|
||||
@ -103,6 +110,7 @@ exports.SendEmail = async function (to, subject, text, html, attachments = []) {
|
||||
.sendMail(message)
|
||||
.then(console.log)
|
||||
.catch(console.error);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
@ -148,6 +156,7 @@ exports.SendEmailHandlebars = async function (to, templateName, model, attachmen
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
Handlebars.logger.error(error);
|
||||
return new Error('Error sending email');
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user