1
votes

I am trying to use SMTP connection with nodemailer with office365 mail.

When I try to send mail, it throws up this error -

Error: connect ETIMEDOUT xx.xxx.xxx.xxx:587 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1161:14) errno: 'ETIMEDOUT', code: 'ECONNECTION', syscall: 'connect', address: 'xx.xxx.xxx.xxx', port: 587

It is not a proxy issue, since I tried outside of the network and it throws up the same error as well.

`

var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
    host: 'smtp.office365.com',
    secure: false,
    auth: {
        user: "[email protected]",
        pass: "xxxxx"
    },
    tls: {
        ciphers: 'SSLv3'
    }
});
var message = {
    from: 'Sender Name <[email protected]>',
    to: '"Receiver Name" <[email protected]>',
    subject: 'Nodemailer',
    text: 'Hello to myself!'
};
transporter.sendMail(message, function(error, response) {
    if (error) {
        console.log('Error occured');
        res.end("<html><body><h1>error</h1></body></html>");
        console.log(error);
        return;
    } else {
        console.log(response);
        res.end("<html><body><h1>success</h1></body></html>");
        console.log('Message sent successfully!');
    }
});

`

I tried with other services as well like Gmail, it also gives the same error inside and outside the network.

2

2 Answers

0
votes

Do you have a local firewall or anti-virus product that does port blocking? My company routinely blocks computers from making outbound connections on common SMTP ports because it was a common multi-mailer virus propagation path. smtp.office365.com responds on both port 25 and 587 from a host I know to be able to initiate outbound SMTP traffic.

[~]# nmap -p25,587 smtp.office365.com

Starting Nmap 7.60 ( https://nmap.org ) at 2018-12-04 10:39 EST
Nmap scan report for smtp.office365.com (40.97.170.178)
Host is up (0.027s latency).

PORT    STATE SERVICE
25/tcp  open  smtp
587/tcp open  submission
0
votes

this might be a bit late but this is more for anyone else in the future.

Common cause for timeouts is you have to enable SMTP, if using a mac this can be done through PowerShell then look to here. If youre on a mac, you'll have to install WSman because it doesnt come with powershell. run on port 587. set secure to false. then make sure your config email and the email in your auth and data for postman are the same.