19

After searching for more than 6 hours trying to understand what is zoho's mail problem to send emails! After i read lots of their answer with no helpful solution, i found the solution is that you need to have the sender option in your NodeMailer option same like email with same sender name and sender email. like this : from: '"senderNameSameLikeTheZohoOne<emailname@yourwebsite.com>',

my config :

const transporter = nodemailer.createTransport({
        service:'Zoho',
        host: 'smtp.zoho.com',
        port: 465,
        secure: true, // use SSL
        auth: {
          user: `${process.env.EMAIL_ADDRESS}`,
          pass: `${process.env.EMAIL_PASSWORD}`
        },
      });
    
      const mailOptions = {
        from: '"senderNameSameLikeTheZohoOne" <emailname@yourwebsite.com>',
        to: `${user.email}`,
        subject: '',
        text:''
         ,
      };

transporter.sendMail(mailOptions, (err, response) => {
        if (err) {
          console.error('there was an error: ', err);
          res.status(401).json(err);
        } else {
          // console.log('here is the res: ', response);
          res.status(200).json('recovery email sent');
        }
      });

hopefully it helps someone

ZohoCoder
  • 385
  • 5
  • 15
heshamelmasry99
  • 380
  • 4
  • 12

2 Answers2

1

This helped me a lot. And to be more specific,

The cause of my error was that the emailname@yourwebsite.com was missing from "from: '"senderNameSameLikeTheZohoOne" emailname@yourwebsite.com'". Immediately I added it, it worked perfectly. Thanks a lot for the clarification

godofjs
  • 93
  • 1
  • 7
0

I spent full night on this ! In my case the email was successfully sent using this command

echo "test-body" | mailx -r senderEamil@tld.com -s "test-subject" reciverEmail@tld.com

But this was not working

echo "test-body" | mailx -s "test-subject" reciverEmail@tld.com

So found that my website is using the host VM user name where it wasn't the same of the sender email smtp config in my postfix

I had two solution

  1. To explictily set a sender username to the postfix check this
  2. Add a user name similar to the sender email at your VM
Abdullah Tahan
  • 1,963
  • 17
  • 28