@@ -10,55 +10,57 @@ const logger = require('../src/common/logger');
10
10
sgMail . setApiKey ( config . SENDGRID_API_KEY ) ;
11
11
12
12
const sendEmail = async ( templateId , message ) => { // send email
13
+ ( await functionWrapper ( async ( ) => {
13
14
14
- let msg = { }
15
- const from = message . from ? message . from : config . EMAIL_FROM ;
16
- const replyTo = message . replyTo ? message . replyTo : config . EMAIL_FROM ;
17
- const substitutions = message . data ;
18
- const categories = message . categories ? message . categories : [ ] ;
19
- const to = message . recipients ;
20
- const cc = message . cc ? message . cc : [ ] ;
21
- const bcc = message . bcc ? message . bcc : [ ] ;
22
- const sendAt = message . sendAt ? message . sendAt : undefined ;
23
- const personalizations = message . personalizations ? message . personalizations : undefined
24
- const attachments = message . attachments ? message . attachments : [ ] ;
15
+ let msg = { }
16
+ const from = message . from ? message . from : config . EMAIL_FROM ;
17
+ const replyTo = message . replyTo ? message . replyTo : config . EMAIL_FROM ;
18
+ const substitutions = message . data ;
19
+ const categories = message . categories ? message . categories : [ ] ;
20
+ const to = message . recipients ;
21
+ const cc = message . cc ? message . cc : [ ] ;
22
+ const bcc = message . bcc ? message . bcc : [ ] ;
23
+ const sendAt = message . sendAt ? message . sendAt : undefined ;
24
+ const personalizations = message . personalizations ? message . personalizations : undefined
25
+ const attachments = message . attachments ? message . attachments : [ ] ;
25
26
26
- if ( message . version && message . version == "v3" ) {
27
- msg = {
28
- to,
29
- templateId,
30
- dynamicTemplateData : substitutions ,
31
- personalizations,
32
- from,
33
- replyTo,
34
- categories,
35
- cc,
36
- bcc,
37
- attachments,
38
- sendAt
39
- } ;
40
- } else {
41
- msg = {
42
- to,
43
- templateId,
44
- substitutions,
45
- substitutionWrappers : [ '{{' , '}}' ] ,
46
- from,
47
- replyTo,
48
- categories,
49
- cc,
50
- bcc,
51
- } ;
52
- }
53
- logger . info ( `Sending email with templateId: ${ templateId } and message: ${ JSON . stringify ( msg ) } ` ) ;
54
- try {
55
- const result = await sgMail . send ( msg )
56
- logger . info ( `Email sent successfully with result: ${ JSON . stringify ( result ) } ` ) ;
57
- return result
58
- } catch ( err ) {
59
- logger . error ( `Error occurred in sendgrid api calling: ${ err } ` ) ;
60
- throw err
61
- }
27
+ if ( message . version && message . version == "v3" ) {
28
+ msg = {
29
+ to,
30
+ templateId,
31
+ dynamicTemplateData : substitutions ,
32
+ personalizations,
33
+ from,
34
+ replyTo,
35
+ categories,
36
+ cc,
37
+ bcc,
38
+ attachments,
39
+ sendAt
40
+ } ;
41
+ } else {
42
+ msg = {
43
+ to,
44
+ templateId,
45
+ substitutions,
46
+ substitutionWrappers : [ '{{' , '}}' ] ,
47
+ from,
48
+ replyTo,
49
+ categories,
50
+ cc,
51
+ bcc,
52
+ } ;
53
+ }
54
+ logger . info ( `Sending email with templateId: ${ templateId } and message: ${ JSON . stringify ( msg ) } ` ) ;
55
+ try {
56
+ const result = await sgMail . send ( msg )
57
+ logger . info ( `Email sent successfully with result: ${ JSON . stringify ( result ) } ` ) ;
58
+ return result
59
+ } catch ( err ) {
60
+ logger . error ( `Error occurred in sendgrid api calling: ${ err } ` ) ;
61
+ throw err
62
+ }
63
+ } , 'sendgridSendEmail' ) ) ( templateId , message ) ;
62
64
}
63
65
module . exports = {
64
66
sendEmail,
0 commit comments