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
610export 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+ // };
0 commit comments