File tree Expand file tree Collapse file tree 3 files changed +22
-14
lines changed Expand file tree Collapse file tree 3 files changed +22
-14
lines changed Original file line number Diff line number Diff line change 37
37
},
38
38
"dependencies" : {
39
39
"@hapi/joi" : " ^16.1.4" ,
40
- "@sendgrid/mail" : " ^7.4.2" ,
41
40
"@topcoder-platform/tc-auth-lib" : " topcoder-platform/tc-auth-lib#1.0.4" ,
42
41
"aos" : " ^2.3.4" ,
43
42
"atob" : " ^2.1.1" ,
Original file line number Diff line number Diff line change 3
3
*/
4
4
import config from 'config' ;
5
5
import { logger } from 'topcoder-react-lib' ;
6
-
7
- const sgMail = require ( '@sendgrid/mail' ) ;
8
-
9
- sgMail . setApiKey ( config . SECRET . SENDGRID_API_KEY ) ;
6
+ import fetch from 'isomorphic-fetch' ;
10
7
11
8
/**
12
9
* Sends emails via the Sendgrid API
13
- * https://sendgrid.com/docs/for-developers/sending-email/quickstart-nodejs/#starting-the-project
10
+ * https://sendgrid.com/docs/api-reference/
14
11
* @param {Object } req the request
15
12
* @param {Object } res the response
16
13
*/
17
14
export const sendEmail = async ( req , res ) => {
18
15
try {
19
16
const msg = req . body ;
20
- // const result = await sgMail.send(msg);
21
- if ( req . query . throw ) throw new Error ( 'tyr/catch error' ) ;
22
- return msg ;
17
+ const response = await fetch ( 'https://api.sendgrid.com/v3/mail/send' , {
18
+ method : 'POST' ,
19
+ headers : {
20
+ 'Content-Type' : 'application/json' ,
21
+ Authorization : `Bearer ${ config . SECRET . SENDGRID_API_KEY } ` ,
22
+ } ,
23
+ body : JSON . stringify ( msg ) ,
24
+ } ) ;
25
+ res . status ( response . status ) ;
26
+ return { } ;
23
27
} catch ( error ) {
24
28
logger . error ( error ) ;
25
29
const { message, code, response } = error ;
Original file line number Diff line number Diff line change @@ -103,11 +103,16 @@ https://www.topcoder.com/gigs/${props.id}`,
103
103
const res = await fetch ( `${ PROXY_ENDPOINT } /mailchimp/email` , {
104
104
method : 'POST' ,
105
105
body : JSON . stringify ( {
106
- from : `${ profile . firstName } ${ profile . lastName } via Topcoder Gigwork <noreply@topcoder.com>` ,
107
- to : formData . email ,
108
- replyTo : 'noreply@topcoder.com' ,
109
- subject : `${ profile . firstName } ${ profile . lastName } Thinks This Topcoder Gig Is For You!` ,
110
- text : formData . body ,
106
+ personalizations : [
107
+ {
108
+ to : [ { email : formData . email } ] ,
109
+ subject : `${ profile . firstName } ${ profile . lastName } Thinks This Topcoder Gig Is For You!` ,
110
+ } ,
111
+ ] ,
112
+ from : { email : 'noreply@topcoder.com' , name : `${ profile . firstName } ${ profile . lastName } via Topcoder Gigwork` } ,
113
+ content : [ {
114
+ type : 'text/plain' , value : formData . body ,
115
+ } ] ,
111
116
} ) ,
112
117
headers : {
113
118
'Content-Type' : 'application/json' ,
You can’t perform that action at this time.
0 commit comments