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?


the sendmail function is in the server.js file,
import form the module nodemailer,
is the server.js file was import to netlify?

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 github repo, you can find my server.js file here, its just a file with all my back 's code:

i didnt write a netlify function, the error should be from here, i goona try it, could you just check the server.js file and tell me if you see something, that could be the source of the problem, (i already deployed some app with this kind of code’s structure and everything was correct)
thank you for your time

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.

ok thank you i gonna work on it,
could you just advice me, you are saying run a node server instance does not work, i would just understand, i have already deployed an app, with this kind of structure, with a server.js file which drive the app,
the link of the repo github:

the lnetlify link:
What is the difference between thoses two apps working?
thanks for your advices

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.