Skip to content

Commit 57b2c2f

Browse files
committed
Sending emails via API directly due lib bug
1 parent f036993 commit 57b2c2f

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
},
3838
"dependencies": {
3939
"@hapi/joi": "^16.1.4",
40-
"@sendgrid/mail": "^7.4.2",
4140
"@topcoder-platform/tc-auth-lib": "topcoder-platform/tc-auth-lib#1.0.4",
4241
"aos": "^2.3.4",
4342
"atob": "^2.1.1",

src/server/services/sendGrid.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,27 @@
33
*/
44
import config from 'config';
55
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';
107

118
/**
129
* 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/
1411
* @param {Object} req the request
1512
* @param {Object} res the response
1613
*/
1714
export const sendEmail = async (req, res) => {
1815
try {
1916
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 {};
2327
} catch (error) {
2428
logger.error(error);
2529
const { message, code, response } = error;

src/shared/containers/Gigs/RecruitCRMJobDetails.jsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,16 @@ https://www.topcoder.com/gigs/${props.id}`,
103103
const res = await fetch(`${PROXY_ENDPOINT}/mailchimp/email`, {
104104
method: 'POST',
105105
body: JSON.stringify({
106-
from: `${profile.firstName} ${profile.lastName} via Topcoder Gigwork <[email protected]>`,
107-
to: formData.email,
108-
replyTo: '[email protected]',
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: '[email protected]', name: `${profile.firstName} ${profile.lastName} via Topcoder Gigwork` },
113+
content: [{
114+
type: 'text/plain', value: formData.body,
115+
}],
111116
}),
112117
headers: {
113118
'Content-Type': 'application/json',

0 commit comments

Comments
 (0)