@@ -2,19 +2,19 @@ import fs from 'node:fs';
2
2
import https from 'https' ;
3
3
import formData from 'form-data' ;
4
4
import Mailgun from 'mailgun.js' ;
5
- import { updateMailCount } from '../../Utils.js' ;
5
+ import { smtpenable , smtpsecure , updateMailCount } from '../../Utils.js' ;
6
6
import sendMailGmailProvider from './sendMailGmailProvider.js' ;
7
7
import { createTransport } from 'nodemailer' ;
8
8
async function sendMailProvider ( req ) {
9
9
try {
10
10
let transporterSMTP ;
11
11
let mailgunClient ;
12
12
let mailgunDomain ;
13
- if ( process . env . SMTP_ENABLE ) {
13
+ if ( smtpenable ) {
14
14
transporterSMTP = createTransport ( {
15
15
host : process . env . SMTP_HOST ,
16
16
port : process . env . SMTP_PORT || 465 ,
17
- secure : process . env . SMTP_SECURE || true ,
17
+ secure : smtpsecure ,
18
18
auth : {
19
19
user : process . env . SMTP_USER_EMAIL ,
20
20
pass : process . env . SMTP_PASS ,
@@ -54,8 +54,8 @@ async function sendMailProvider(req) {
54
54
const pdfName = req . params . pdfName && `${ req . params . pdfName } .pdf` ;
55
55
const file = {
56
56
filename : pdfName || 'exported.pdf' ,
57
- content : process . env . SMTP_ENABLE ? PdfBuffer : undefined , //fs.readFileSync('./exports/exported_file_1223.pdf'),
58
- data : process . env . SMTP_ENABLE ? undefined : PdfBuffer ,
57
+ content : smtpenable ? PdfBuffer : undefined , //fs.readFileSync('./exports/exported_file_1223.pdf'),
58
+ data : smtpenable ? undefined : PdfBuffer ,
59
59
} ;
60
60
61
61
let attachment ;
@@ -64,27 +64,25 @@ async function sendMailProvider(req) {
64
64
const certificateBuffer = fs . readFileSync ( './exports/certificate.pdf' ) ;
65
65
const certificate = {
66
66
filename : 'certificate.pdf' ,
67
- content : process . env . SMTP_ENABLE ? certificateBuffer : undefined , //fs.readFileSync('./exports/exported_file_1223.pdf'),
68
- data : process . env . SMTP_ENABLE ? undefined : certificateBuffer ,
67
+ content : smtpenable ? certificateBuffer : undefined , //fs.readFileSync('./exports/exported_file_1223.pdf'),
68
+ data : smtpenable ? undefined : certificateBuffer ,
69
69
} ;
70
70
attachment = [ file , certificate ] ;
71
71
} catch ( err ) {
72
72
attachment = [ file ] ;
73
73
console . log ( 'Err in read certificate sendmailv3' , err ) ;
74
74
}
75
75
const from = req . params . from || '' ;
76
- const mailsender = process . env . SMTP_ENABLE
77
- ? process . env . SMTP_USER_EMAIL
78
- : process . env . MAILGUN_SENDER ;
76
+ const mailsender = smtpenable ? process . env . SMTP_USER_EMAIL : process . env . MAILGUN_SENDER ;
79
77
80
78
const messageParams = {
81
79
from : from + ' <' + mailsender + '>' ,
82
80
to : req . params . recipient ,
83
81
subject : req . params . subject ,
84
82
text : req . params . text || 'mail' ,
85
83
html : req . params . html || '' ,
86
- attachments : process . env . SMTP_ENABLE ? attachment : undefined ,
87
- attachment : process . env . SMTP_ENABLE ? undefined : attachment ,
84
+ attachments : smtpenable ? attachment : undefined ,
85
+ attachment : smtpenable ? undefined : attachment ,
88
86
} ;
89
87
if ( transporterSMTP ) {
90
88
const res = await transporterSMTP . sendMail ( messageParams ) ;
@@ -120,9 +118,7 @@ async function sendMailProvider(req) {
120
118
}
121
119
} else {
122
120
const from = req . params . from || '' ;
123
- const mailsender = process . env . SMTP_ENABLE
124
- ? process . env . SMTP_USER_EMAIL
125
- : process . env . MAILGUN_SENDER ;
121
+ const mailsender = smtpenable ? process . env . SMTP_USER_EMAIL : process . env . MAILGUN_SENDER ;
126
122
127
123
const messageParams = {
128
124
from : from + ' <' + mailsender + '>' ,
0 commit comments