My issue is with properly configuring Nodemailer with an Exchange 2010 email server on a Node.js application.
Because I'm not getting an authentication issue, which I do when using well-known services like Outlook365, I'm assuming the problem is with the host and/or security and port settings - I don't think I connect in the first place.
My config below -
let transporter = nodemailer.createTransport({
host: 'https://email.<COMPANYNAME>.com/owa',
port: '587',
secure: false,
auth: {
user: <USERNAME>,
pass: <PASSWORD>
},
tls: {
rejectUnauthorized: false
}
});
It errors here on my Node app -
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.log('Send error: ', error);
res.sendStatus(500);
} else {
console.log('Email sent!');
res.sendStatus(200);
}
});
Here is the error from AWS EC2 logs -
getaddrinfo ENOTFOUND https://email.<COMPANYNAME>.com/owa https://email.<COMPANYNAME>.com/owa:587
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
code: 'ECONNECTION',
errno: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'https://email.<COMPANYNAME>.com/owa',
host: 'https://email.<COMPANYNAME>.com/owa',
port: '587',
command: 'CONN'
Nodemailer docs specify that the host "is the hostname or IP address to connect to (defaults to ‘localhost’)"
When I try more the conventional mail.COMPANYNAME.com my requests time out. Using the address clearly hits my server and returns errors in the verification/ sending steps that I've specified.
Again, the issue seems to be with my transporter configuration with Exchange 2010. Any help is greatly appreciated!
I was searching for this question too. But I found the solution myself.
const transporter = nodemailer.createTransport({
host: 'smtp.office365.com',
port: 587,
secure: false,
auth: {
user: 'USER_NAME',
pass: 'PASSWORD'
}
});
I used this configuration for sending email using node mailer from exchange or Office 365 server.
Related
How can i send mail from node js with the use of my domail mail like as : noreply#example.com
The connection setting was below using nodemailer
const transporter = nodemailer.createTransport({
host: 'https://example.com',
port: 465, // Port
secure: true, // this is true as port is 465
auth: {
user: 'noreply#example.com',
pass: 'mypassword'
}
});
If i send mail there is an error like below
Error: getaddrinfo ENOTFOUND https://example.com
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26) {
errno: -3008,
code: 'EDNS',
syscall: 'getaddrinfo',
hostname: 'https://lvkart.com',
command: 'CONN'
}
I had this issue when I accedentally added a trailing space to the hostname. The problem seems to be the failing DNS lookup.
In your example: The https:// part is not part of the hostname. In fact, you use SMTP protocol, not https.
try
const transporter = nodemailer.createTransport({
host: 'example.com', // Whatever your true hostname is. Could also be smtp.example.com or similar.
port: 465, // Port
secure: true, // this is true as port is 465
auth: {
user: 'noreply#example.com',
pass: 'mypassword'
}
});
I think the problem might come from your SMTP.
check your configuration correct or wrong by using (outlook or google mail).
I'm trying to use Nodemailer in Node.js with Google OAuth2, using port: 465, secure: true. But I'm receiving the error message below:
Error: connect ECONNREFUSED 127.0.0.1:587
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1137:16) {
errno: -61,
code: 'ESOCKET',
syscall: 'connect',
address: '127.0.0.1',
port: 587,
command: 'CONN'
}
As you can see... Port 587 is coming in the error message, but it wasn't defined anywhere in my app.
In my previous configuration, I was using Nodemailer with Node.js, port: 587, secure: false, rejectUnauthorized: false. And it worked like a charm.
However, Nodemailer is defaulting to 587 for some reason. It may be my fault, but I'm declaring port: 465 with secure: true. And, according to their documentation, it only defaults to 587 if you type secure: false.
Here's my configuration:
async function sendEmail() {
try {
const REDIRECT_URI = config.redirect_uri;
const oAuth2Client = new google.auth.OAuth2(config.mailClientID,
config.mailClientSecret, REDIRECT_URI);
oAuth2Client.setCredentials({refresh_token: config.refresh_token});
const accessToken = await oAuth2Client.getAccessToken();
let smtpConfigWithToken = nodemailer.createTransport({
service: 'Gmail',
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
type: 'OAuth2',
user: config.email,
clientId: config.mailClientID,
clientSecret: config.mailClientSecret,
refreshToken: config.refresh_token,
accessToken: accessToken
}
});
let transporter = nodemailer.createTransport(smtpConfigWithToken);
let HelperOptions = {
from: '<birthmet#themetropolitanschool.com>',
to: emailRecipients,
bcc: '<lgranados#themetropolitanschool.com>',
subject: "New Birthday Cake request",
html: output
};
const result = transporter.sendMail(HelperOptions);
return result;
} catch(err) {
return err;
}
}
sendEmail().then(result => console.log('Email sent...', result)).catch(err => console.log(err));
I can always go back, but I'm putting a good effort into making my apps more secure. I very much prefer not to enable "Less Secure Apps".
Note: the URI is also verified by Google.
As a troubleshoot step, I've run the sample code from Google and I can get the labels, as well as token.json. See this link for Node.js code. My app also needs access to Spreadsheets, but that part is working flawlessly (using the same token credentials).
Can you help me with a solution on this wrong port error?
Thank you in advance for taking your time reading this.
I think port: 465 is no longer in use for SMTP
instead use either port: 587, or port: 2525,
Of course... It was my own fault.
I declared nodemailer.createTransport in smtpConfigWithToken and in transporter.
Looks like I've been staring at the screen for too long.
No wonder why Nodemailer went crazy with an error message that I've never seen before.
Well, at least it's documented. If you see an error -61 with Nodemailer, then please check that you don't have multiple instances of nodemailer.createTransport.
It's all working now.
I have been using nodemailer to send emails from my node js app, it used to work perfectly on localhost and it still does. I deployed the server to my online host, it didn't work giving me this error
{ Error: connect ECONNREFUSED 172.253.112.108:465
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1174:14)
errno: 'ECONNREFUSED',
code: 'ECONNECTION',
syscall: 'connect',
address: '172.253.112.108',
port: 465,
command: 'CONN' }
I have tried to look for solutions (XOauth2, using older version of nodemailer, setting environment variables) but none are working! what should i do to resolve this?
I had the config below:
let transporter = nodemailer.createTransport({
name: mydomain.com,
pool: true,
host: mydomain.com, //as recommended by my host provider
port: 465,
secure: true,
auth: {
user: info#mydomain.com,
pass: MAILER_PASSWORD,
},
tls: {
rejectUnauthorized: false,
},
});
The problem was with accessing the port 465 on the host.
changed my config to following solved the problem:
let transporter = nodemailer.createTransport({
name: mydomain.com,
pool: true,
host: mail.mydomain.com, //<----change
port: 587, //<----change
secure: false, //<----change
auth: {
user: info#mydomain.com,
pass: MAILER_PASSWORD,
},
tls: {
rejectUnauthorized: false,
},
});
I want to send email via Gmail or other email provider like office 365 using Nodemailer as my module Node.js.
I wanna ask also if there's a proxy or firewall setting to disable so that I can send email using gmail or office 365.
Or maybe there is something wrong with my code ?
const nodemailer = require("nodemailer");
const smtpTransport = require('nodemailer-smtp-transport');
function sendEmail(to, subject, html){
nodemailer.createTestAccount((err, account) => {
let transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
user: 'philip#gmail.com',
pass: 'sercretpass'
}
});
let mailOptions = {
from: '"Admin" ',
to: to,
subject: subject,
html: html
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.log('Error', error);
}
else{
console.log('Success', info);
}
});
});
}
module.exports.sendEmail = sendEmail;
MY ERROR :
Error { Error: connect ETIMEDOUT 74.125.203.108:465
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1121:14)
errno: 'ETIMEDOUT',
code: 'ECONNECTION',
syscall: 'connect',
address: '74.125.203.108',
port: 465,
command: 'CONN' }
Are you able to telnet to smtp.gmail.com from the machine on port 465 ?
Also try with Port 587, with 587, you should see some other error as it works on STARTTLS.
TESTED WORKING ON GMAIL 2022 March
STEP 1- Enable the "Less Secure App Access" from Security Page of the Google Account
. Google says It's no longer supported but turn On
the feature anyway.
STEP 2-Turn Off the google CAPTCHA.
STTEP 3- Configuring Port And HOST
**Do not use google as the host.Refer the following.
host: "smtp.gmail.com"
if port 587 is not working, try port 465. Make sure to make secure:true for port 465
let transporter = nodemailer.createTransport({
host: "smtp.gmail.com",
port: 465,
secure: true,
auth: {
user: 'youremail#gmail.com',
pass: 'password',
},
// enable below only if u are running on local host
tls: { rejectUnauthorized: true }
});
I always used nodemailer for sending emails, suddenly I started having the above error. So I thought what was new on the computer and found that the antivirus was causing the problem. So disabling the antivirus and windows firewall is a good start to solve the problem.
I'm trying to use nodemailer send the email. Below is the sample code.
const nodemailer = require('nodemailer');
let transporter = nodemailer.createTransport({
host: '10.88.88.88',
port: 25,
secureConnection: false,
auth: {
user: 'user',
pass: 'pwd',
}
});
let mailOptions = {
from: 'sender#test.com', // sender address
to: 'receiver#test.com', // list of receivers
subject: 'Hello', // Subject line
html: '<b>Hello world?</b>' // html body
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log(error);
}
console.log('Message sent: %s', info.messageId);
});
However I got the error below. It seems I could not access the server. The server is using smtp relay of IIS. What is the exact user/pass in auth here? The server window user account who has the right to access the smtp service? If I change user/pass to mailaddress/password, I got the same error info. If I remove auth, I still got the same error info. Or it is proxy issue?
{ Error: connect EACCES 10.88.88.88:25
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1113:14)
errno: 'EACCES',
code: 'ECONNECTION',
syscall: 'connect',
address: '10.88.88.88,
port: 25,
command: 'CONN' }
The servers infra is like below:
node server <--> SMTP Relay IIS (10.88.88.88) <--> Mailserver
Please check using port 587 instead of 25.