@@ -68,28 +68,26 @@ const makeEmail = async (to, from, subject, html, url, pdfName) => {
68
68
type : 'application/pdf' ,
69
69
path : './exports/certificate.pdf' ,
70
70
} ;
71
- attachments = [ file , certificate ] ;
71
+ if ( fs . existsSync ( certificate . path ) ) {
72
+ attachments = [ file , certificate ] ;
73
+ } else {
74
+ attachments = [ file ] ;
75
+ }
72
76
} catch ( err ) {
73
77
attachments = [ file ] ;
74
78
console . log ( 'Err in read certificate sendmailv3' , err ) ;
75
79
}
76
80
}
77
81
const attachmentParts = attachments . map ( attachment => {
78
- if ( fs . existsSync ( attachment . path ) ) {
79
- try {
80
- const content = fs . readFileSync ( attachment . path ) ;
81
- const encodedContent = content . toString ( 'base64' ) ;
82
- return [
83
- `Content-Type: ${ attachment . type } \n` ,
84
- 'MIME-Version: 1.0\n' ,
85
- `Content-Disposition: attachment; filename="${ attachment . filename } "\n` ,
86
- `Content-Transfer-Encoding: base64\n\n` ,
87
- `${ encodedContent } \n` ,
88
- ] . join ( '' ) ;
89
- } catch ( err ) {
90
- console . log ( 'Err in read attachments sendmailv3' , attachment . path ) ;
91
- }
92
- }
82
+ const content = fs . readFileSync ( attachment . path ) ;
83
+ const encodedContent = content . toString ( 'base64' ) ;
84
+ return [
85
+ `Content-Type: ${ attachment . type } \n` ,
86
+ 'MIME-Version: 1.0\n' ,
87
+ `Content-Disposition: attachment; filename="${ attachment . filename } "\n` ,
88
+ `Content-Transfer-Encoding: base64\n\n` ,
89
+ `${ encodedContent } \n` ,
90
+ ] . join ( '' ) ;
93
91
} ) ;
94
92
95
93
const attachmentBody = attachmentParts . join ( `\n--${ boundary } \n` ) ;
@@ -149,6 +147,14 @@ export default async function sendMailGmailProvider(_extRes, template) {
149
147
} ,
150
148
} ) ;
151
149
console . log ( 'gmail provider res: ' , response ?. status ) ;
150
+ const certificatePath = './exports/certificate.pdf' ;
151
+ if ( fs . existsSync ( certificatePath ) ) {
152
+ try {
153
+ fs . unlinkSync ( certificatePath ) ;
154
+ } catch ( err ) {
155
+ console . log ( 'Err in unlink certificate sendmailgmail provider' ) ;
156
+ }
157
+ }
152
158
return { code : 200 , message : 'Email sent successfully' } ;
153
159
} catch ( error ) {
154
160
console . error ( 'Error sending email:' , error ) ;
0 commit comments