Zoho mail is working properly on localhost but not on the live server with nodemailer
ContactForm.jsx
- import React, { useState, useEffect } from 'react'
- const ContactForm = () => {
- const [fname, setFname] = useState("");
- const [lname, setLname] = useState("");
- const [email, setEmail] = useState("");
- const [subject, setSubject] = useState("");
- const [msg, setMsg] = useState("");
- const [message, setMessage] = useState('');
- useEffect(() => {
- setTimeout(function () {
- setMessage(true)
- }, 9000);
- },
- [message])
- const sendEmail = async (e) => {
- e.preventDefault();
- setFname("");
- setLname("");
- setEmail("");
- setSubject("");
- setMsg("");
- setMessage(`Thank you ${fname} ${lname} for enquiry. We will back to you asap.`);
- const res = await fetch("/register", {
- method: "POST",
- headers: {
- "Content-Type": "application/json"
- }, body: JSON.stringify({
- fname, lname, email, subject, msg
- })
- });
- console.log(res);
- }
- return (
- <>
- <div className="contact-form">
- <div className="contact-form-info">
- <div className="contact-title">
- <h3>TELL US YOUR PROJECT</h3>
- </div>
- <form id="contact-form">
- <div className="contact-page-form">
- <div className="contact-input">
- <div className="contact-inner">
- <input type="text" placeholder="First Name *" id="first-name" value={fname} onChange={(e) => setFname(e.target.value)} />
- </div>
- <div className="contact-inner">
- <input type="text" placeholder="Last Name *" id="last-name" value={lname} onChange={(e) => setLname(e.target.value)} />
- </div>
- <div className="contact-inner">
- <input type="text" placeholder="Email *" id="email" value={email} onChange={(e) => setEmail(e.target.value)} />
- </div>
- <div className="contact-inner">
- <input type="text" placeholder="Subject *" id="subject" value={subject} onChange={(e) => setSubject(e.target.value)} />
- </div>
- <div className="contact-inner contact-message">
- <textarea placeholder="Message *" value={msg} onChange={(e) => setMsg(e.target.value)}></textarea>
- </div>
- </div>
- <div className="contact-submit-btn">
- <button className="submit-btn" type="submit" onClick={sendEmail} >Send Email</button>
- <p className="form-messege pt-3">{message}</p>
- </div>
- </div>
- </form>
- </div>
- </div>
- </>
- )
- }
- export default ContactForm;
app.js
- const express = require("express");
- const app = express();
- const router = require("./routes/router");
- const cors = require("cors");
- const port = 8000
- app.use(express.json());
- app.use(cors());
- app.use(router);
- app.listen(port,()=>{
- console.log(`Server start on port no : ${port}`)
- })
- const express = require("express");
- const router = new express.Router();
- const nodemailer = require("nodemailer");
- router.post("/register", (req, res) => {
- const { fname, lname, email, subject, msg } = req.body;
- try {
- let transporter = nodemailer.createTransport({
- host: "smtppro.zoho.in",
- port: 465,
- secure: true, // true for 465, false for other ports
- auth: {
- user: "info@mydomain.com",
- pass: "myAppPassword",
- },
- });
- const mailOptions = {
- from: "info@mydomain.com",
- cc: "info@mydomain.com",
- to: email,
- subject: "Website Form",
- html: 'First Name : ' + fname + '<br>' +
- 'Last Name : ' + lname + '<br>' +
- 'Email : ' + email + '<br>' +
- 'Subject : ' + subject + '<br>' +
- 'Message : ' + msg
- }
- transporter.sendMail(mailOptions, (error, info) => {
- if (error) {
- console.log("Error", error)
- } else {
- console.log("Email sent" + info.response);
- res.status(201).json({ status: 201, info })
- }
- })
- } catch (error) {
- res.status(401).json({ status: 401, error })
- }
- });
module.exports = router;
I have been using nodemailer to send emails from my react and node js app, it used to work perfectly on localhost. I deployed to my hosting, it didn't work. Giving this.
Access your files securely from anywhere
Zoho Developer Community
Deliver unforgettable customer experiences
Deliver unforgettable customer experiences
New to Zoho Marketing Plus?
Everything you need to run your marketing
New to Zoho Marketing Plus?
Everything you need to run your marketing
Zoho Desk Resources
-
Desk Community Learning Series
-
-
-
-
-
-
-
-
-
Sticky Posts
Zoho Mail POP & IMAP Server Details
Hello all! We have been receiving a number of requests regarding the errors while configuring or using Zoho Mail account in POP/ IMAP clients. The server details vary based on your account type and the Datacenter in which your account is setup. Ensure
Important update on Group Management | Zoho Mail
Dear Zoho Mail Community, This post is to inform you all of the following updates on the Group Management in Zoho Mail. Group Member Addition: If a group member is added to an organization group in a Zoho Application, the member will be automatically
Mastering email etiquette and best practices to follow in Zoho Mail
Hello Zoho Mail Community, We’re thrilled to invite you all to our upcoming webinar: Mastering email etiquette and best practices to follow in Zoho Mail. Join our live webinar for expert etiquette tips to enhance your professionalism and elevate your
📣 📣 ZUG Meetups India - Explore Hybrid Workspaces using Zoho Workplace - Meet and Learn! 🧑🏽💻🧑🏽💻
We are excited to announce the User Community initiative to meet you all in person and help you explore the need of the hour - Hybrid Workspaces using Zoho Workplace. We aim to help you to setup your Digital Workplace effectively so that your employees
Announcing Zoho Mail - Inactive user Policy
Dear Zoho Mail users, Thanks to all of you for your continuous support. We have recently started implementing the Inactive User Policy, for Zoho Mail. A user is considered as inactive, if the user has not logged in to the Zoho mail account for a period of more than 120 days. The login through POP, IMAP and Active Sync are all taken into account for tracking the period of inactivity. Whoever received the communication need not panic, as we have just communicated our policy to all the users. To
Zoho TeamInbox Resources
Zoho DataPrep Resources
Zoho CRM Plus Resources
Zoho Books Resources
Zoho Subscriptions Resources
Zoho Projects Resources
Zoho Sprints Resources
Qntrl Resources
Zoho Creator Resources
Zoho Campaigns Resources
Zoho CRM Resources
Zoho Show Resources
Writer Get Started. Write Away!
Writer is a powerful online word processor, designed for collaborative work.