4

Below is my code. This works fine with gmail smtp server. But when I use my office one (which does not require authentication) it fails

May be the syntax I am using is wrong.

below is the code working with gmail smtp:


    var mailOptions = {
        from: 'xxxx@abcd.com',
        to: 'xxxxyy@abcd.com',
        subject: 'hello world!',
        html: '<img src="cid:logo">',
        attachments: [{
            filename: 'test.png',
            path: 'D:/bbbbb/mmmm/src/test.png',
            cid: 'logo' //same cid value as in the html img src
        }]
    };

    transport.sendMail(mailOptions, (error, info) => {
        if (error) {
            console.log(error);
        }
        console.log(`Message sent: ${info.response}`);
    }); 

As Our company smtp does not require authentication, I have tried below code:

 var transport = nodemailer.createTransport("smtps://xxxx@abcd.com:"+encodeURIComponent('') + "@xxxx.xxxrxx.com:25");

OR

var transport = nodemailer.createTransport("smtps://xxx.xxx.com:25");

but all resulted error

{ Error: 101057795:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:openssl\ssl\s23_clnt.c:797:

at Error (native) code: 'ECONNECTION', command: 'CONN' }

My guess is syntax is wrong. Can some one pls correct me

Thanks and Regards.

GuZzie
  • 974
  • 1
  • 6
  • 23
Subh
  • 41
  • 1
  • 1
  • 4

1 Answers1

2

You can remove auth option from the example code when creating an SMTP Transport message.

so it should look like the following:

  /**
   * Initialize transport object
   */
  const transporter = nodemailer.createTransport({
    host: "", //Host
    port: , // Port 
    secure: true
  });

    let mailOptions = {
      from: , // sender address
      to: , // list of receivers
      subject: , // Subject line
      text: , // plain text body
      html: // html body
    };

    /**
     * send mail with defined transport object
     */
    transporter.sendMail(mailOptions,
      (error, info) => {

      });
Kunal
  • 125
  • 1
  • 5