'Sending mail from express server not working on live host, in local it works fine

Here is my express app with mail trigger:

const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const nodemailer = require('nodemailer');

const app = express();
app.use(express.static(__dirname+'/public'));
app.use(express.urlencoded({ extended: true }))
app.use(express.json());
app.use(cors());

app.post("/send_mail", cors(), async (req, res) => {
    let {text} = req.body;
    const transporter = nodemailer.createTransport({
        service: 'gmail',
        auth: {
            user: "xxxxxxx",
            pass: "xxxxxxx"
        }
    });

    let message = {
        from: "[email protected]",
        to: "[email protected]",
        subject: "Enquiry from Deane Project Management",
        html: `
        <hr />
            <h1>Request for: ${text.option||"No title"}</h1>
            <span>Name: ${text.username}</span><br/>
            <span>Email: ${text.email}</span><br/>
            <span>Phone: ${text.phone||"No phone"}</span><br/>
            <span>Message:</span><br/>
            <p>${text.message||"No message"}</p>
        <hr />
        `
    }

    transporter.sendMail(message, function(err, info) {
        if (err) {
          console.log(err);
        } else {
          console.log('sent',info);
        }
      });

    res.send(200);
})

app.listen(process.env.PORT || 4000, () => {
    console.log("port listning on port number 4000", process.env.PORT);
})

all this is working fine with my localhost:4000 but after I upload(hosted) with my godaddy account, my app works and getting success message. but did not get any mail with my box. what is the issue? any config requiem either way?

please help me.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source