| 6 | import SMTPTransport from "nodemailer/lib/smtp-transport"; |
| 7 | |
| 8 | function createEmailClient() { |
| 9 | const emailConfig = config.getRawConfig().email; |
| 10 | if (!emailConfig) { |
| 11 | logger.warn( |
| 12 | "Email SMTP configuration is missing. Emails will not be sent." |
| 13 | ); |
| 14 | return; |
| 15 | } |
| 16 | |
| 17 | const settings = { |
| 18 | host: emailConfig.smtp_host, |
| 19 | port: emailConfig.smtp_port, |
| 20 | secure: emailConfig.smtp_secure || false, |
| 21 | auth: |
| 22 | emailConfig.smtp_user && emailConfig.smtp_pass |
| 23 | ? { |
| 24 | user: emailConfig.smtp_user, |
| 25 | pass: emailConfig.smtp_pass |
| 26 | } |
| 27 | : null |
| 28 | } as SMTPTransport.Options; |
| 29 | |
| 30 | if (emailConfig.smtp_tls_reject_unauthorized !== undefined) { |
| 31 | settings.tls = { |
| 32 | rejectUnauthorized: emailConfig.smtp_tls_reject_unauthorized |
| 33 | }; |
| 34 | } |
| 35 | |
| 36 | return nodemailer.createTransport(settings); |
| 37 | } |
| 38 | |
| 39 | export const emailClient = createEmailClient(); |
| 40 | |