Next.js Discord

Discord Forum

New to Vercel. Please help!!

Answered
Yacare Caiman posted this in #help-forum
Open in Discord
Yacare CaimanOP
Hi all! This might be a silly question but I'm new to vercel and need help. I am volunteering for an organization and I'm working for a ticket where I have to handle e-mail confirmation (after submitting a form, the user should get an email confirmation). I wanted to do it via EmailJS but the owner of the organization told me that all the emails are handled via Vercel. I have no idea how to proceed given that I just learned about Vercel. What should I ask the engineer? Thanks in advance.
Answered by Northeast Congo Lion
you are using pages router
View full answer

23 Replies

can tap into serverless function and have the api route trigger the email
Yacare CaimanOP
Thanks so much for replying, @Northeast Congo Lion ! I don't see the backend code on the repo, I just see the frontend code so I don't know where to create the API routes, should I ask the main engineer about it?
Northeast Congo Lion
if u are not confident with touching the code, yes.
you might have normal form inside react which submits from inside client.
but general approach is to put anything like that inside an api route.
this is roughly how it would work

src
  app
    api [folder]
      email [folder]
        confirm [folder]
          route.js
    layout.js [file]
    ...
then inside route.js is where ur logic for nodemailer goes
then inside react form:

const handleSubmit = () => {

  //submit ur form, then call below code in callback
  ...
  fetch('/api/email/confirm', {
    method: 'POST',
    body: {
      email: 'email' //whatever fields u need
    }
  }).then(res => res.json())
   .then(data => { //email confirm sent });
   .catch(err => { //handle error })
}
roughly
Yacare CaimanOP
Thank you! This is the structure of the app:
I don't see the routes in here
Northeast Congo Lion
inside pages
@Yacare Caiman Click to see attachment
Northeast Congo Lion
you are using pages router
Answer
Northeast Congo Lion
if ur stuck, check the docs 🙂
make sure to select the pages router docs at top left
Yacare CaimanOP
I found the routes! Thanks so much!!! I'll read the docs. Thanks a lot!
@Yacare Caiman I found the routes! Thanks so much!!! I'll read the docs. Thanks a lot!
Northeast Congo Lion
sure, mark as solved please and if ur stuck again just open a new issue 🙂
@Yacare Caiman I found the routes! Thanks so much!!! I'll read the docs. Thanks a lot!
Northeast Congo Lion
you can right click the Next.js Forum and mark as solved!
Yacare CaimanOP
I'll do that