Dude you're such a lifesaver. I was making this way too complicated trying to use the Gmail API and Express and knew there had to be an easier way with using Next. Thank you!
@kby9001 Жыл бұрын
I wanted to ask, in my application I'm wanting to take the users email that they input and send the mail directly to them instead of myself. How would i pass that value from the form into mailOptions?
@nikita-dev Жыл бұрын
you can remove the "to" prop from the mailOptions and just set it in the sendMail() call in the handler. In that case, you would be setting the "to" property on the fly, on every request, with whatever the user passed to you in the body. If you take this approach, I would add stronger email validation (using a validation library) to ensure that the user sent a valid email before calling sendMail()
@anasazkoul4899 Жыл бұрын
@@nikita-dev I came across your video wanting to learn about nodemailer and I ended up learning alot more, I'm using zod in my handler to validate emails would think this is a good way to validate the email? looking forward for more videos about nextjs, thank you so much
@nikita-dev Жыл бұрын
No problem! And yes, Zod should be sufficient for email validation
@Abhinav_5383 Жыл бұрын
Bro, JUST the same thing I was trying to do. I spent 4 hours and got just frustrated and dropped the idea.
@СергейМурин-д6ч Жыл бұрын
after 5 hours of trying different options, i finally found the best one
@PrayingLotus Жыл бұрын
Thank you so much for this. Was bashing my head against a wall trying to figure out how to send an email without using a paid service. What I'm wondering now is how, whoever submitted the form, they get a confirmation email as well.
@nikita-dev Жыл бұрын
you can call the sendMail method again, but just override the "to" property with the user's email that they input. For example: await transporter.sendMail({ ...mailOptions, ...generateEmailContent(data), subject: data.subject, to: RECIPIENT_EMAIL }); (replace RECIPIENT_EMAIL with the data that was passed from the user)
@keyonlewis7574 Жыл бұрын
it was fun making this work on next.js 13, lot of new things i learn within 2 hour it take for me to finish it. thanks bro
@Sport-word Жыл бұрын
Hello keyonlevis. i have been trying to make it work on nextjs 13. However, i have not been able to get it right. Please kindly help me with your code. I will deeply appreciate you. Thanks
@defdev007 Жыл бұрын
I've been trying to integrate this feature ever since, but I couldn't find anything that worked for me. Thanks a lot for sharing
@Phas0ruk Жыл бұрын
One issue I had was that my windows firewall was blocking outgoing connections on port 465 which is what gmail uses. When running my app locally, when I temporarily disable the firewall, it works.
@stephanvandermeijden767 Жыл бұрын
Thank you, I ran into issue with Express and whatnot and it just got too complicated. This makes way more sense. Great explaination too!
@nikita-dev Жыл бұрын
thank you, I'm glad it was helpful!
@zee_designs11 ай бұрын
Hey Nikita, you guided me in the right way, I was struggling with this topic, Thank you
@Jediknightcode Жыл бұрын
Great tutorial, thanks for posting this. There is a lot of ends and outs to this process and this video helped give a great guide to getting me toward the track I need!
@nikita-dev Жыл бұрын
I’m glad it was helpful!
@m.efremova4649 Жыл бұрын
This is exactly what I've been looking for! ❤
@NiteshKumar-l8t7m2 ай бұрын
feedback: if you add required thing when user submit and field is empty. This will make much more easier.
@maxskewes Жыл бұрын
Thank you, any possibility of a follow up to this video, migrating to the Nextjs 13 App directory? I am having an absolutely impossible time trying to implement the teachings of this video to their new system of API usage. Much, much appreciated.
@Phas0ruk Жыл бұрын
Superb content. Clear and slick. Keep it up!
@juanrios3066 Жыл бұрын
Perfectly explained and definetely a huge help on my learning journey as a developer, Thank You!!
@Riexn Жыл бұрын
An elegant solution, and well explained. Thanks!
@uminhtetoo Жыл бұрын
Thank you so much for sharing your experience, Sir.
@ssdasasdasdasdsd Жыл бұрын
Awesome video, my guy. You the man!!!! Keep em coming
@setoseng Жыл бұрын
Great explanation! Straight to the point.
@kray85 Жыл бұрын
Awesome tutorial!! Well explained and you saved me hours for implementing a email handler!!
@noone-dx6tr Жыл бұрын
Hey, thanks for the video! Could you also make a tutorial on how to additionally send an attachment via this form and nodemailer?
@noone-dx6tr Жыл бұрын
Please let me know what you think, I Have looked up on the internet and could not find much help, there are also not answered questions about it on stack overflow, so this video could help a lot of people
@nikita-dev Жыл бұрын
I will definitely consider it!
@noone-dx6tr Жыл бұрын
Thank you!
@xlgablx Жыл бұрын
@@nikita-dev :(
@Jesus-xp6cf Жыл бұрын
Thanks for the help!! Amazing tutorial.😁
@INVICTUSasw9 ай бұрын
THIS TUTORIAL WAS HELPFUL !!
@minipark69722 жыл бұрын
Wow, Thank you so much!
@bespokeprogramming10 ай бұрын
You are a legend. Thank you!
@gogaimerlishvili4542 Жыл бұрын
Bravo!
@tonycreavin Жыл бұрын
Great tutorial. One question though. I would like to send the automated confirmation email to the client, rather than to myself. How do you adjust the mailOptions function to allow this? Thanks in advance
@nikita-dev Жыл бұрын
You would have to overwrite the "to" property in the mailOptions object. You will have to do that dynamically on each request. For example: await transporter.sendMail({ ...mailOptions, ...generateEmailContent(data), subject: data.subject, to: RECIPIENT_EMAIL }); (replace RECIPIENT_EMAIL with the data that was passed from the user)
@oghenevwefepeace2501 Жыл бұрын
Nice video, It worked perfectly, Thank You
@manishchaurasia447 Жыл бұрын
Dude you're great. This helped me a lot❤❤❤❤
@techlightdev Жыл бұрын
Thank you for create amazing clearly tutorial. So helpful for me.
@jakubkurdziel2407 Жыл бұрын
Great!
@SergioSanchez-rh4po Жыл бұрын
Super helpful, thank you very much. Keep up the good work!
@nikita-dev Жыл бұрын
thank you!
@almakay01 Жыл бұрын
Also thanks for posting repo it annoys me when people dont do so lol
@Igor-uz3vn Жыл бұрын
Greate tutorial! How did you solve the problem of sending a message from Vercel hosting?
@nikita-dev Жыл бұрын
You just have to make sure your environment variables are set up correctly. If you change them at all, make sure to rebuild the environment so it can pull in the updated values
@evanmarshall9498 Жыл бұрын
I followed this video verbatim and it works flawlessly. Well, I adapted it a bit to use TailwindCSS for the contact form but still works great... locally. When I push to my production deployment on Vercel and test it live, it does not work. I added the environment variables (EMAIL & EMAIL_PASS) to Vercel settings thinking that was the issue, but still no fix. Can anybody help me with this? Does anybody have similar issues? EDIT: Needed to perform a new deployment after adding Envrionment Variables to Vercel in order to update the site with the variables. Ran a test and it works!! Thank you!
@pedro.sh101 Жыл бұрын
hi Evan, could you explain a little better how you made it work? having the same issue here, but on netlify
@evanmarshall9498 Жыл бұрын
@@pedro.sh101 I was only updating locally so in order to update in production I needed to push a new deployment to vercel in order for the environment variable to take place.
@gubmx209 ай бұрын
I had to do the same thing!
@score_ Жыл бұрын
everything works perfectly fine, just a question, is this api/contact public for everyone when we host it? Is there a risk of this data being leaked?
@TheRiteHand Жыл бұрын
Awesome tutorial. Question: how do we supply env variables in production? Thanks in advance for any help!!
@nikita-dev Жыл бұрын
It depends on where you deploy (Netlify, Vercel). There is usually a tab in your configuration settings called "Environment Variables". You should be able to find detailed steps by looking through the docs of the cloud company you are using (to deploy).
@sagar5547 Жыл бұрын
thank you so much bro lots of love . it helped me in my porject. 🥰
@CodeInDraw11 ай бұрын
Thank you so much. Its really helpful
@andersbraathen1256 Жыл бұрын
Great video, thanks!
@ManuelGuillenSerna6 ай бұрын
Thank you so much for the video, it really helped make my contact form. The only issue that i have is that, even though i have my type="email" on the email input, i can write whatever (without an @) and the email is still sent. It isn't a big problem but i would really appreciate if you could help me with this. Thank you!
@sudam-d8 ай бұрын
Appreciate this so much
@KubaSobecki Жыл бұрын
Very helpful. Subbed. Thank you.
@iamcherrycloud Жыл бұрын
Thank you so much, your video helped me a lot
@neutrallane Жыл бұрын
Its not working on my end... i followed everything
@nikita-dev Жыл бұрын
what part specifically is not working?
@vito71982 жыл бұрын
Thanks!
@ahmedhassaballa9909 Жыл бұрын
Thanks for your great explanation, i would like to ask can i adapt this approach in my project for sending email notification within my workplace for workflow tasks such as approval email notifications when a new request has created by employees ? regards
@nikita-dev Жыл бұрын
Yes, you can reuse the same nodemailer client to send emails for various different actions that you want to handle in your app. The only thing that would change is the email content
@Abhinav_5383 Жыл бұрын
Just Awesome
@박공부-m5h7 ай бұрын
멋진 튜토리얼 입니다.
@aliazeem92Ай бұрын
Thanks bro, you helped very well
@cacodelphia_2 ай бұрын
awesome man, thank you
@scoria4988 Жыл бұрын
Hi Onelight! I like your solution since I was trying to get a functionality like this using services like sendgrid but all of these require you to have a private email domain which I can't affort right now. But I do have a question, I implemented your solution almost identically to yours with almost the same validations: isn't it kind of a vulnerability that an user can spam the send button or creating a script to completely flood your inbox? If that's the case, what can I do to prevent that from happening?
@c4pancake8 ай бұрын
If using newer versions of Next.js, would you just add "use client" to the top? Or would you do this a different way?
@johnmichaelcanero2210 Жыл бұрын
Thank you! It worked but HOW do you set up where the sender displays their name in the email and not the "Me" Email?
@wild3dcgi969 Жыл бұрын
thx u a lot man for such awesome tutorial
@SF-tv2so9 ай бұрын
Thank u so much. Ur video has helped me
@Califv Жыл бұрын
thanks!
@subei7418 Жыл бұрын
Why is nodemailer not sending the email when deploying on Vercel?
@nikita-dev Жыл бұрын
it is likely an issue with your environment variables
@oketunbiolufunke11424 күн бұрын
@@nikita-devalso facing same issue and it’s not the Environment variables When I deploy to vercel I get an error and the whole application crashes
@princefresh75884 күн бұрын
@@oketunbiolufunke1142 does this video works ? on local host ?
@clarkwayne21028 ай бұрын
Thank you so much!
@srinivasnahak34737 ай бұрын
Thank you so muchhh!!
@AbdullahShahid-n5g3 күн бұрын
is it a only front end based email sender mean do you need express or backend to able to run it or is it purely frontend based
@nikita-dev3 күн бұрын
The email is getting sent from the server (NextJS API function), not the frontend. So you don’t need express
@SubwaySounds Жыл бұрын
Awesome thanks.
@SubhadipBisai Жыл бұрын
if I want to change "from" and "to" for differnet mail then this EMAIL_PASS pin is needed for both mail ?? how can i do that?
@nikita-dev Жыл бұрын
you will only need to change the EMAIL_PASS variable for the sender's email (the "from" email). Yo don't need a password for the "to" email
@jackpaterson53246 ай бұрын
it works👍
@danielChibuogwu Жыл бұрын
I really appreciate it
@jayeshsingh2810 ай бұрын
Chakraui updated docs disabled for button is now isDisabled hope it helps✌🏻🔥
@gojamoja6719 Жыл бұрын
thanks man
@naveenv841717 күн бұрын
i have deployed my portfolio in vercel which had this nodemailer in localhost it is working perfectly but after deployment is showing error with 500 code
@zaqwer95955 күн бұрын
Have you entered auth data (the one from .env.local file) to Vercel's environment variables in project settings?
@user-nn8ui8rx7j Жыл бұрын
Could you make a version of this video that does not rely upon chakara?
@mydaily21 Жыл бұрын
about template. is possible if import template email.html to api? not copy all code from template. i mean just import it
@MohammadbasitYousofi-ih5iv Жыл бұрын
Hey! Error: fs not found from node_modules folder of node mailer tell me the sulotion
@muhammedshibil54095 ай бұрын
Hi, how to solve Error.can you share
@kikonunez290 Жыл бұрын
Thank you for the tutorial! I got everything working until the very end. The contact form works on my localhost but not on my deployment link with Vercel. I keep getting "Failed to send message" using my deployment link. Any idea why?
@kikonunez290 Жыл бұрын
using the chrome dev tools, there is a network error saying ""Missing credentials for \"PLAIN\""
@nikita-dev Жыл бұрын
It is likely an issue with your environment variables. Can you verify that they are set properly and you’re able to access them from the Vercel app? (Create a test endpoint that returns some of the non-sensitive env variables like the email and ensure that you get back the right value)
@kikonunez290 Жыл бұрын
@@nikita-dev Thank you so much, that did the trick! I needed to add my env variables to my vercel app.
@atsglobalservices6136 Жыл бұрын
Great video
@amitodak7 ай бұрын
hi, do you tutorial or other resources that have for file upload in pdf format? thank you
@Sport-word Жыл бұрын
This is not working on nextjs 13. latest version. Please help
@MdNaimurRahmanHera2 ай бұрын
Awesome
@Lyzeuph11 ай бұрын
Thank you!!!!
@appstuff65656 ай бұрын
Hey Nikita thanks for this. Im using Nextjs and supabase and im now requiring to use a smtp, for sending sign up and reset emails only, so what do you think is the best way to do about this? Nodemailer + Amazon SES? or can I just use nodemailer alone
@nikita-dev6 ай бұрын
Honestly I would recommend just using AWS SES or Resend
@appstuff65656 ай бұрын
@@nikita-dev thanks nikita.
@RaulGlasgow11 ай бұрын
good job!
@yuvalbra Жыл бұрын
how can i add attachment file? and where i need to put the file if i want to send it ?
@jankarlodeiparine5360 Жыл бұрын
I hope I get a reply from this. I can't seem to accomplish it via using Outlook, it sends me error code 535 5.7.139 Authentication unsuccessful. I'm doing a blind approach on this configuration. Please I do need help on this matter.
@nikita-dev Жыл бұрын
Here is a helpful article on using Nodemailer with Outlook: ourcodeworld.com/articles/read/264/how-to-send-an-email-gmail-outlook-and-zoho-using-nodemailer-in-node-js
@JBUDDTV Жыл бұрын
is the spinning annimation part of Chakra-ui or embedded into nexjs?
@nikita-dev Жыл бұрын
it's part of Chakra UI
@lorenprice7333 Жыл бұрын
Get tutorial! But I have an error on my end. It's saying: Cannot read properties of undefined (reading 'sendMail') at handler. How do I fix this?
@nikita-dev Жыл бұрын
it looks like your transporter object is not being imported correctly. Are you exporting from the config/nodemailer.js file?
@lorenprice7333 Жыл бұрын
@@nikita-dev Thank you, I went back and copied exactly what you had and it finally worked. I must have had a typo somewhere. Thank you for responding!! Also, great tutorial not get! lol
@lorenprice7333 Жыл бұрын
@@nikita-dev Would you be willing to give me advise on transferring this to an existing project. I'm now getting an error stating it cannot resolve 'nodemailer'. The error suggest trying a 'preferRelative' . How would I add this to the config/nodemailer file?
@nikita-dev Жыл бұрын
did you install the nodemailer package from NPM? (in your other project)
@lipocodes2273 Жыл бұрын
Very good
@sayakbasak587 Жыл бұрын
great
@juanbecher6200 Жыл бұрын
Hey thanks for the video! I’m having some issues moving to production since the send email function is taking more than 10 sec to run which makes that vercel stop the execution due to limitations on the free plan. Do you think it could be a solution for this? Thanks in advance!
@nikita-dev Жыл бұрын
It shouldn't take more than 10sec to run... Im assuming there's an error in your API route. Are you able to check the server logs and see if there are any errors that are logged?
@AdamBakerMTB Жыл бұрын
@@nikita-dev It will be returning a 504 because if its hosted on vercel it could be doing a "cold start", causing the resource to time out?
@AdamBakerMTB Жыл бұрын
Did you find a solution to this?
@juanbecher6200 Жыл бұрын
@@AdamBakerMTB not really. I ended up using sendgrid.
@RahulSingh-on7ko4 ай бұрын
hi i am facing issue with fetch the contact api . 400 bad request coming export const sendContactForm = async (data) => fetch('api/contact', { method: "POST", body: JSON.stringify(data), headers: { "Content-Type": "application/json", Accept: "application/json" }, }).then((res) => { if (!res.ok) throw new Error("Failed to send message"); return res.json(); });
@sdfsdfsdffdsfsdfsd123 Жыл бұрын
How can I fixed this? thanks
@devpako1899 Жыл бұрын
Good job, but I need help if you can. I want to use this form to send email with attachment or embedded image. Nodemailer has an example for it but that example uses locally stored images which is not what I need. I need user to be able to upload picture and send it to email. Please give me some guidance.
@nikita-dev Жыл бұрын
You'll have to first store the image somewhere (S3, or whatever cloud provider you're using), then get the public URL to that image and use that to create an image in the email HTML. This logic can all be done in the handler
@MaikeHerzog11 ай бұрын
works local but not working on server "gateway timeout 504"
@NoomanMILED Жыл бұрын
Hi, thx a lot !, just not working in production. Mail received with "undefined" instead of req.body value
@nikita-dev Жыл бұрын
were you able to get it working locally?
@formorri Жыл бұрын
@@nikita-dev I'm having the same problem. It works locally but if I deploy to Amplify, it doesn't work. I've tried entering the env variables into Amplify but even then it gives me a 405 error.
@daviddarfdas Жыл бұрын
@@formorri Same issue here. Could this be gmail blocking the request?
@arounaouattara60376 ай бұрын
Thanks
@godzabomni4148 Жыл бұрын
Can you use this to send to outlook emails?
@nikita-dev Жыл бұрын
yup! you can find some examples online: ourcodeworld.com/articles/read/264/how-to-send-an-email-gmail-outlook-and-zoho-using-nodemailer-in-node-js
@mikegyamfi983 Жыл бұрын
It sends message undefined undefined to my gmail..how do I fix this?
@mikegyamfi983 Жыл бұрын
The stringData comes out as undefined
@treyrader5 ай бұрын
Is this possible to setup without using 2F auth? If so, do i just ommit the pass variable? Having some issues with getting it to work. Might have to rabbit hole for the night
@nikita-dev5 ай бұрын
honestly I would recommend using Resend instead of Nodemailer
@treyrader5 ай бұрын
@@nikita-dev isn't resend not free? I'll look into it for sure. thanks man
@nikita-dev5 ай бұрын
they have a pretty generous free tier
@aniket10084 ай бұрын
@@nikita-dev Don't we need to add domain in order to send emails from any place. Would have to buy domains right?
@geta70 Жыл бұрын
for me, it doesn't work and I don't know why. l receive the message " Failed to send message" also I receive the next Error: Missing credentials for "PLAIN"
@nikita-dev Жыл бұрын
This is likely an issue with your environment variables. Are you able to get it working locally by hard coding the values into your nodemailer instance?
@wolfie87484 ай бұрын
but this is basically me messaging me ? when I check who sent the email it is the user we entered so how can random people mail me for my portfolio website?
@nikita-dev4 ай бұрын
You’ll have to rely on the email sent in the form field to know who submitted the contact form. Sure the user can pass a fake or invalid email in that field, but if they really want you to get back to them, it will be a valid email. If you want the email to come from the user who is actually contacting you, you should use an HTML email link: with href set to: mailto:myemail@gmail.com This will open the users default email client and allow them to send an email to you directly.
@wolfie87484 ай бұрын
@@nikita-dev thank you very much!
@suhaib789 Жыл бұрын
Error: Connection timeout code: 'ETIMEOUT', command: 'CONN' Please tell me how i can solve this error.
@nikita-dev Жыл бұрын
when are you getting this error?
@shrutishende4819 Жыл бұрын
its not working for me . i mean locally its send message but when i push code using vercel it failed to send message
@nikita-dev Жыл бұрын
are you using environment variables properly? And what email provider are you using?
@shrutishende4819 Жыл бұрын
@@nikita-dev yess.. now its working .. i have to set env varriable in vercel. btw thank you so much for this video. its very helpful and i am using it in my personal poertfolio website.
@CodingSnippets2.0 Жыл бұрын
Sir when I deploy this aap to firebase hosting nodemailer does not send an email..please reply
@nikita-dev Жыл бұрын
This is because firebase hosting only supports static files (not SSR pages or API routes). It's possible to host your entire Next App (or just API routes) through Firebase functions, but it gets pretty complicated. I would recommend sticking with Vercel or Netlify for deploying NextJS apps. More details here: stackoverflow.com/questions/70992583/nextjs-api-routes-not-working-with-firebase-hosting
@CodingSnippets2.0 Жыл бұрын
@@nikita-dev can we host APIs which build in next js like in api folder to vercel?
@nikita-dev Жыл бұрын
yes, Vercel supports SSR and API routes
@elitkondor7371 Жыл бұрын
As far as I could tell, gmail does not support media queries