mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-12 23:35:58 +00:00
refactor(backend): set up smtp pooling for nodemailer (#8167)
* backend: active SMTP pooling in Nodemailer configuration * backend: add max SMTPconnections and messages to Nodemailer configuration * move transport outside function to ensure pooling can work --------- Co-authored-by: Ulf Gebhardt <ulf.gebhardt@webcraft-media.de>
This commit is contained in:
parent
04bf693453
commit
7d9b0e6437
@ -12,6 +12,8 @@ EMAIL_DEFAULT_SENDER="devops@ocelot.social"
|
||||
SMTP_HOST=
|
||||
SMTP_PORT=
|
||||
SMTP_IGNORE_TLS=true
|
||||
SMTP_MAX_CONNECTIONS=5
|
||||
SMTP_MAX_MESSAGES=Infinity
|
||||
SMTP_USERNAME=
|
||||
SMTP_PASSWORD=
|
||||
SMTP_SECURE="false" # true for 465, false for other ports
|
||||
|
||||
@ -57,6 +57,8 @@ const smtp = {
|
||||
SMTP_DKIM_KEYSELECTOR: hasDKIMData && env.SMTP_DKIM_KEYSELECTOR,
|
||||
// PEM format: https://docs.progress.com/bundle/datadirect-hybrid-data-pipeline-installation-46/page/PEM-file-format.html
|
||||
SMTP_DKIM_PRIVATKEY: hasDKIMData && env.SMTP_DKIM_PRIVATKEY.replace(/\\n/g, '\n'), // replace all "\n" in .env string by real line break
|
||||
SMTP_MAX_CONNECTIONS: env.SMTP_MAX_CONNECTIONS || 5,
|
||||
SMTP_MAX_MESSAGES: env.SMTP_MAX_MESSAGES || 100,
|
||||
}
|
||||
|
||||
const neo4j = {
|
||||
|
||||
@ -9,6 +9,25 @@ const hasAuthData = CONFIG.SMTP_USERNAME && CONFIG.SMTP_PASSWORD
|
||||
const hasDKIMData =
|
||||
CONFIG.SMTP_DKIM_DOMAINNAME && CONFIG.SMTP_DKIM_KEYSELECTOR && CONFIG.SMTP_DKIM_PRIVATKEY
|
||||
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: CONFIG.SMTP_HOST,
|
||||
port: CONFIG.SMTP_PORT,
|
||||
ignoreTLS: CONFIG.SMTP_IGNORE_TLS,
|
||||
secure: CONFIG.SMTP_SECURE, // true for 465, false for other ports
|
||||
pool: true,
|
||||
maxConnections: CONFIG.SMTP_MAX_CONNECTIONS,
|
||||
maxMessages: CONFIG.SMTP_MAX_MESSAGES,
|
||||
auth: hasAuthData && {
|
||||
user: CONFIG.SMTP_USERNAME,
|
||||
pass: CONFIG.SMTP_PASSWORD,
|
||||
},
|
||||
dkim: hasDKIMData && {
|
||||
domainName: CONFIG.SMTP_DKIM_DOMAINNAME,
|
||||
keySelector: CONFIG.SMTP_DKIM_KEYSELECTOR,
|
||||
privateKey: CONFIG.SMTP_DKIM_PRIVATKEY,
|
||||
},
|
||||
})
|
||||
|
||||
let sendMailCallback: any = async () => {}
|
||||
if (!hasEmailConfig) {
|
||||
if (!CONFIG.TEST) {
|
||||
@ -38,22 +57,6 @@ if (!hasEmailConfig) {
|
||||
}
|
||||
} else {
|
||||
sendMailCallback = async (templateArgs) => {
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: CONFIG.SMTP_HOST,
|
||||
port: CONFIG.SMTP_PORT,
|
||||
ignoreTLS: CONFIG.SMTP_IGNORE_TLS,
|
||||
secure: CONFIG.SMTP_SECURE, // true for 465, false for other ports
|
||||
auth: hasAuthData && {
|
||||
user: CONFIG.SMTP_USERNAME,
|
||||
pass: CONFIG.SMTP_PASSWORD,
|
||||
},
|
||||
dkim: hasDKIMData && {
|
||||
domainName: CONFIG.SMTP_DKIM_DOMAINNAME,
|
||||
keySelector: CONFIG.SMTP_DKIM_KEYSELECTOR,
|
||||
privateKey: CONFIG.SMTP_DKIM_PRIVATKEY,
|
||||
},
|
||||
})
|
||||
|
||||
transporter.use(
|
||||
'compile',
|
||||
htmlToText({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user