|
1 | 1 | // Sends email to hello@webdevpath.co when user submit the form in "Contact Us" page |
2 | | -import sendgrid from '@sendgrid/mail'; |
3 | 2 |
|
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 | +}); |
5 | 9 |
|
6 | 10 | export default async (email, name, subject, message, subscribe) => { |
7 | | - 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'; |
| 11 | + // receiverEmail: The email will be sent here |
| 12 | + const receiverEmail = 'hello@webdevpath.co'; |
14 | 13 |
|
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 | | - `; |
| 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'; |
22 | 18 |
|
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: [ |
| 19 | + try { |
| 20 | + const data = { |
| 21 | + Messages: [ |
35 | 22 | { |
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 | + `, |
38 | 40 | }, |
39 | 41 | ], |
40 | 42 | }; |
41 | | - await sendgrid.send(emailMessage); |
| 43 | + |
| 44 | + await mailjet.post('send', { version: 'v3.1' }).request(data); |
| 45 | + |
42 | 46 | return { |
43 | 47 | status: 'okay', |
44 | 48 | }; |
|
0 commit comments