Problem in production with nodemailer


I have encountered a problem with my app after deployed it, I’m using nodemailer package to send an email from a website. Everything works fine in development and I’m able to receive mail from the site, but in a production environment, i got a 404 error status on my request

the netlify site name is


const contact = {

        contactForm : document.querySelector('.contact-form'),
        email : document.querySelector(".contact-email"),
        message : document.querySelector(".contact-text"),
        emailState : document.getElementById("input-hidden"),
        server_url : "/.netlify/functions/sendmail"


    listener: function(){
         contact.dataForm.contactForm.addEventListener('submit', contact.actionListener.handleSubmit)

    actionListener: {

        handleSubmit : (e) => {
                headers: {
                    'Content-Type': 'application/json'
                body: JSON.stringify(
                    datas: {
                        message: contact.dataForm.message.value                  

            .then(res => {

                    .then(data => {
                        window.alert("Votre email a bien été envoyé")
               = '';
                        contact.dataForm.message.value = '';
                    console.log("There is a problem with nodemailer")
            .catch(function(error) {
                console.log('There is a problem with the fetch operation: ' + error.message);

    errorResponse: function(){
        window.alert("Une erreur est survenue, merci d'utiliser le lien Linkedin") = '';
        contact.dataForm.message.value = '';
document.addEventListener('DOMContentLoaded', contact.initContact);

i have just changed the server_url from my localhost to

server_url : "/.netlify/functions/sendmail"

i found informations on this post, but not really sure its appropriate to my code, problem coub be from here

back:'/',(req,res) => { 
        const transporter = nodemailer.createTransport({
            host: "",
            port: 465,
            secure: true,
                user: process.env.GMAIL_USER,
                pass: process.env.PASSWORD,

        const mailOptions = {
            to: process.env.GMAIL_USER,
            subject: "email from my Portfolio",
            html: `You got a message from 
            Email : ${} <br>
            Message: ${req.body.datas.message}`,
        transporter.sendMail(mailOptions, (error, info) => {
            res.json({email:"email sent"})

        res.json({message: error})

As i said, in developement i got no probleme, i recieve the email with all the informations, after some researchs and differents trials, with no success, i am asking some advices,
Please let me know if any other information needs in order to help solve my problem.
Thank you.


It appears the sendmail function does not actually exist. Does the deploy log show the function was build and deployed alongside the rest of your site?


What is the server.js file? It is not possible to run a server on Netlify. You can only use serverless functions

Can you share the repository you are deploying?

The server.js file is, as evidenced by the following line from the package.json

"start": "node server.js"

won’t (as mentioned previously) work as is on Netlify. Running a node server instance does not work.

You can use express in a serverless function as shown in How to run Express.js apps with Netlify Functions.

You don’t need to use Express JS. A less-than-perfect example written by myself is available here if you wish to use/reference it.

The server.js is this site is doing nothing. If you recall the discussion from here where you set the publish directory to public, this means that anything at the root of the repository is not deployed. Only the static assets inside the public directory are deployed and served.

The same with this new portfolio site, if you set the public directory as the publish directory in the build settings, the server.js file is ignored.

For this site, if you wish to have a function to send an email via nodemailer, create a netlify/functions directory at the root of the repository, and inside this place the function. Set the publish directory to public and Netlify will deploy this and automatically build and deploy the function(s).

As mentioned previously, you can use express js inside a serverless function if you desire.