Skip to content

Commit 0942092

Browse files
committed
swap sendgrid for mailjet
1 parent baac3fb commit 0942092

File tree

4 files changed

+137
-34
lines changed

4 files changed

+137
-34
lines changed

.env-template

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ MAILCHIMP_API_KEY={Add the key}
77
MAILCHIMP_AUDIENCE_ID={Add the ID}
88
NEXT_PUBLIC_RECAPTCHA_SITE_KEY={Add the key}
99
RECAPTCHA_SECRET_KEY={Add the key}
10-
SENDGRID_API_KEY={Add the key}
11-
NEXT_PUBLIC_GA_MEASUREMENT_ID={Add the key}
10+
NEXT_PUBLIC_GA_MEASUREMENT_ID={Add the key}
11+
MAILJET_API_KEY={Add the key}
12+
MAILJET_API_SECRET={Add the key}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"html-entities": "^2.3.2",
2424
"next": "^15.3.2",
2525
"next-pwa": "^5.6.0",
26+
"node-mailjet": "^6.0.9",
2627
"react": "^19.1.0",
2728
"react-dom": "^19.1.0",
2829
"react-google-recaptcha": "^3.1.0",

pages/api/sendEmail.js

Lines changed: 87 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,48 @@
11
// Sends email to hello@webdevpath.co when user submit the form in "Contact Us" page
2-
import sendgrid from '@sendgrid/mail';
32

4-
sendgrid.setApiKey(process.env.SENDGRID_API_KEY);
3+
import { Client } from 'node-mailjet';
4+
5+
const mailjet = new Client({
6+
apiKey: process.env.MAILJET_API_KEY,
7+
apiSecret: process.env.MAILJET_API_SECRET,
8+
});
59

610
export default async (email, name, subject, message, subscribe) => {
11+
// receiverEmail: The email will be sent here
12+
const receiverEmail = 'hello@webdevpath.co';
13+
14+
// mailJetEmail: This is the email verified by mailjet
15+
// the email will appear to be sent from this email
16+
// If a non-verified email is used, it just fails silently
17+
const mailjetEmail = 'support@webdevpath.co';
18+
719
try {
8-
// receiverEmail: The email will be sent here
9-
const receiverEmail = 'hello@webdevpath.co';
10-
// sendgridEmail: This is the email verfied by sendgrid
11-
// the email will appear to be sent from this email
12-
// If a non verified email is used, we get a 403 error
13-
const sendgridEmail = 'support@webdevpath.co';
14-
15-
const emailContent = `
16-
<b>Name:</b> ${name} <br/>
17-
<b>Email:</b> <a href='mailto:${email}'>${email}</a><br/><br/>
18-
<u><b>Subject:</b> ${subject}</u><br/>
19-
<b>Message:</b> ${message} <br/>
20-
<b>Subscribe?:</b> ${subscribe ? 'Yes' : 'No'}
21-
`;
22-
23-
const emailMessage = {
24-
to: receiverEmail,
25-
from: {
26-
email: sendgridEmail,
27-
name: 'Web Dev Path',
28-
},
29-
replyTo: {
30-
email,
31-
name,
32-
},
33-
subject: `New message from ${name} via webdevpath.co 'Contact Us' Form`,
34-
content: [
20+
const data = {
21+
Messages: [
3522
{
36-
type: 'text/html',
37-
value: emailContent,
23+
From: {
24+
Email: mailjetEmail,
25+
name: 'Web Dev Path',
26+
},
27+
To: [
28+
{
29+
Email: receiverEmail,
30+
},
31+
],
32+
Subject: `New message from ${name} via webdevpath.co 'Contact Us' Form`,
33+
HTMLPart: `
34+
<b>Name:</b> ${name} <br/>
35+
<b>Email:</b> <a href='mailto:${email}'>${email}</a><br/><br/>
36+
<u><b>Subject:</b> ${subject}</u><br/>
37+
<b>Message:</b> ${message} <br/>
38+
<b>Subscribe?:</b> ${subscribe ? 'Yes' : 'No'}
39+
`,
3840
},
3941
],
4042
};
41-
await sendgrid.send(emailMessage);
43+
44+
await mailjet.post('send', { version: 'v3.1' }).request(data);
45+
4246
return {
4347
status: 'okay',
4448
};
@@ -49,3 +53,54 @@ export default async (email, name, subject, message, subscribe) => {
4953
};
5054
}
5155
};
56+
57+
// import sendgrid from '@sendgrid/mail';
58+
//
59+
// sendgrid.setApiKey(process.env.SENDGRID_API_KEY);
60+
//
61+
// export default async (email, name, subject, message, subscribe) => {
62+
// try {
63+
// // receiverEmail: The email will be sent here
64+
// const receiverEmail = 'hello@webdevpath.co';
65+
// // sendgridEmail: This is the email verfied by sendgrid
66+
// // the email will appear to be sent from this email
67+
// // If a non verified email is used, we get a 403 error
68+
// const sendgridEmail = 'support@webdevpath.co';
69+
//
70+
// const emailContent = `
71+
// <b>Name:</b> ${name} <br/>
72+
// <b>Email:</b> <a href='mailto:${email}'>${email}</a><br/><br/>
73+
// <u><b>Subject:</b> ${subject}</u><br/>
74+
// <b>Message:</b> ${message} <br/>
75+
// <b>Subscribe?:</b> ${subscribe ? 'Yes' : 'No'}
76+
// `;
77+
//
78+
// const emailMessage = {
79+
// to: receiverEmail,
80+
// from: {
81+
// email: sendgridEmail,
82+
// name: 'Web Dev Path',
83+
// },
84+
// replyTo: {
85+
// email,
86+
// name,
87+
// },
88+
// subject: `New message from ${name} via webdevpath.co 'Contact Us' Form`,
89+
// content: [
90+
// {
91+
// type: 'text/html',
92+
// value: emailContent,
93+
// },
94+
// ],
95+
// };
96+
// await sendgrid.send(emailMessage);
97+
// return {
98+
// status: 'okay',
99+
// };
100+
// } catch (e) {
101+
// return {
102+
// status: 'error',
103+
// message: `Error: ${e.message}`,
104+
// };
105+
// }
106+
// };

yarn.lock

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,6 +1590,15 @@ available-typed-arrays@^1.0.7:
15901590
dependencies:
15911591
possible-typed-array-names "^1.0.0"
15921592

1593+
axios@^1.8.1:
1594+
version "1.11.0"
1595+
resolved "https://registry.yarnpkg.com/axios/-/axios-1.11.0.tgz#c2ec219e35e414c025b2095e8b8280278478fdb6"
1596+
integrity sha512-1Lx3WLFQWm3ooKDYZD1eXmoGO9fxYQjrycfHFC8P0sCfQVXyROp0p9PFWBehewBOdCwHc+f/b8I0fMto5eSfwA==
1597+
dependencies:
1598+
follow-redirects "^1.15.6"
1599+
form-data "^4.0.4"
1600+
proxy-from-env "^1.1.0"
1601+
15931602
axios@^1.8.2:
15941603
version "1.9.0"
15951604
resolved "https://registry.yarnpkg.com/axios/-/axios-1.9.0.tgz#25534e3b72b54540077d33046f77e3b8d7081901"
@@ -1654,6 +1663,11 @@ big.js@^5.2.2:
16541663
resolved "https://registry.yarnpkg.com/big.js/-/big.js-5.2.2.tgz#65f0af382f578bcdc742bd9c281e9cb2d7768328"
16551664
integrity sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ==
16561665

1666+
bignumber.js@^9.0.0:
1667+
version "9.3.1"
1668+
resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-9.3.1.tgz#759c5aaddf2ffdc4f154f7b493e1c8770f88c4d7"
1669+
integrity sha512-Ko0uX15oIUS7wJ3Rb30Fs6SkVbLmPBAKdlm7q9+ak9bbIeFf0MwuBsQV6z7+X768/cHsfg+WlysDWJcmthjsjQ==
1670+
16571671
brace-expansion@^1.1.7:
16581672
version "1.1.11"
16591673
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
@@ -2291,6 +2305,17 @@ form-data@^4.0.0:
22912305
es-set-tostringtag "^2.1.0"
22922306
mime-types "^2.1.12"
22932307

2308+
form-data@^4.0.4:
2309+
version "4.0.4"
2310+
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.4.tgz#784cdcce0669a9d68e94d11ac4eea98088edd2c4"
2311+
integrity sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow==
2312+
dependencies:
2313+
asynckit "^0.4.0"
2314+
combined-stream "^1.0.8"
2315+
es-set-tostringtag "^2.1.0"
2316+
hasown "^2.0.2"
2317+
mime-types "^2.1.12"
2318+
22942319
fs-extra@^9.0.1:
22952320
version "9.1.0"
22962321
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.1.0.tgz#5954460c764a8da2094ba3554bf839e6b9a7c86d"
@@ -2849,6 +2874,13 @@ jsesc@~3.0.2:
28492874
resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-3.0.2.tgz#bb8b09a6597ba426425f2e4a07245c3d00b9343e"
28502875
integrity sha512-xKqzzWXDttJuOcawBt4KnKHHIf5oQ/Cxax+0PWFG+DFDgHNAdi+TXECADI+RYiFUMmx8792xsMbbgXj4CwnP4g==
28512876

2877+
json-bigint@^1.0.0:
2878+
version "1.0.0"
2879+
resolved "https://registry.yarnpkg.com/json-bigint/-/json-bigint-1.0.0.tgz#ae547823ac0cad8398667f8cd9ef4730f5b01ff1"
2880+
integrity sha512-SiPv/8VpZuWbvLSMtTDU8hEfrZWg/mH/nV/b4o0CYbSxu1UIQPLdwKOCIyLQX+VIPO5vrLX3i8qtqFyhdPSUSQ==
2881+
dependencies:
2882+
bignumber.js "^9.0.0"
2883+
28522884
json-parse-even-better-errors@^2.3.1:
28532885
version "2.3.1"
28542886
resolved "https://registry.yarnpkg.com/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz#7c47805a94319928e05777405dc12e1f7a4ee02d"
@@ -3133,6 +3165,15 @@ node-addon-api@^7.0.0:
31333165
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-7.1.1.tgz#1aba6693b0f255258a049d621329329322aad558"
31343166
integrity sha512-5m3bsyrjFWE1xf7nz7YXdN4udnVtXK6/Yfgn5qnahL6bCkf2yKt4k3nuTKAtT4r3IG8JNR2ncsIMdZuAzJjHQQ==
31353167

3168+
node-mailjet@^6.0.9:
3169+
version "6.0.9"
3170+
resolved "https://registry.yarnpkg.com/node-mailjet/-/node-mailjet-6.0.9.tgz#6ae26b3192f66c49c8536ed98a80b755afe28b26"
3171+
integrity sha512-WGovS3g+2R/02IkD9/EWNvItRVhei7ltmh40JN53cozna41Ug/T3oKOAehBnV0B6Egx1H6L565HbeffUE7DYWg==
3172+
dependencies:
3173+
axios "^1.8.1"
3174+
json-bigint "^1.0.0"
3175+
url-join "^4.0.0"
3176+
31363177
node-releases@^2.0.19:
31373178
version "2.0.19"
31383179
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.19.tgz#9e445a52950951ec4d177d843af370b411caf314"
@@ -4189,6 +4230,11 @@ uri-js@^4.2.2:
41894230
dependencies:
41904231
punycode "^2.1.0"
41914232

4233+
url-join@^4.0.0:
4234+
version "4.0.1"
4235+
resolved "https://registry.yarnpkg.com/url-join/-/url-join-4.0.1.tgz#b642e21a2646808ffa178c4c5fda39844e12cde7"
4236+
integrity sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA==
4237+
41924238
watchpack@^2.4.1:
41934239
version "2.4.2"
41944240
resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-2.4.2.tgz#2feeaed67412e7c33184e5a79ca738fbd38564da"

0 commit comments

Comments
 (0)