I am using nodemailer module to send mail from my nodejs application.
I am getting Error: connect ETIMEDOUT xxx.xxx.xx.xxx:465. Can any one help me in solving this.
Here I am pasting my code.
var transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: 'my_mail_id#gmail.com',
pass: 'my_gmail_password'
}
});
console.log('created');
transporter.sendMail({
from: 'my_mail_id#gmail.com',
to: 'my_mail_id#gmail.com',
subject: 'hello world!',
text: 'hello world!'
});
This may be firewall problem. I faced similar problem in Ubuntu (Digital Ocean server). Tried to fix the issue for 3 days, tried using auth2 also, tried with inactive firewall using ufw inactive command, but no luck. Finally I checked Digital Ocean admin panel and created firewall for the droplet. Problem solved by enabling TCP inbound and outbound in firewall settings.
Have you looked at this answer.
It turns out that in order for Google to authorize a third party server to access your account via SMTP now, you have to enable “Less Secure Apps” on your gmail account, if you want to use username/password (more info here).
So you have two option:
use OAuth
make your account less secure
// Create a SMTP transport object
var transport = nodemailer.createTransport("SMTP", {
service: 'Hotmail',
auth: {
user: "username",
pass: "paasweord"
}
});
console.log('SMTP Configured');
// Message object
var message = {
// sender info
from: 'abc#hotmail.com',
// Comma separated list of recipients
to: req.query.to //'aadityashukla9#hotmail.com',
// Subject of the message
subject:req.query.subject //'Nodemailer is unicode friendly ✔',
// plaintext body
text: req.query.text //'Hello to myself!',
// HTML body
/* html:'<p><b>Hello</b> to myself <img src="cid:note#node"/></p>'+
'<p>Here\'s a nyan cat for you as an embedded attachment:<br/></p>'*/
};
console.log('Sending Mail');
transport.sendMail(message, function(error){
if(error){
console.log('Error occured');
console.log(error.message);
return;
}
console.log('Message sent successfully!');
//transport.close(); // close the connection pool
});
I experienced this same issue today, found this documentation...
https://nodemailer.com/usage/using-gmail/
Had to do a capcha process from the server, by visiting a url while logged into gmail.
Hopefully it helps others.
There are the only reasons of this error:
Less Secure Apps: you have to Enable the "Less Secure Apps" from your Gmail account.
Use OAuth
Besides the already mentioned reference to the information at https://nodemailer.com/usage/using-gmail/, in my case the Internet Router (Speedport W724V) was still a problem. This keeps a list of all allowed SMTP servers. After I had extended the list accordingly, it worked perfectly. I had to do the same with smtp.ethereal.email.
I'm not sure if should be posting this answer but I've faced the same problem while using GMAIL and the reason behind the error for me was being connected to a vpn. I disabled it and now it works.
I'm using an application password
open port inbound outbound rule 587 or others, whichever you are using on server aws/google etc.
host: host,
secureConnection: false,
port: 465,
secure: true,
auth: {
user: user,
pass: pass
}
Related
I'm building a nodejs method that will connect to an Office365 Outlook email inbox and retrieve all unread emails. It uses the nodejs-imap library to achieve this. This is my config for imap:
const imapConfig = {
user: process.env.EMAIL_USER,
password: process.env.EMAIL_PASS,
host: 'outlook.office365.com',
port: 993,
debug: console.log,
tls: true,
};
Sadly when I try connecting to the server I receive these logs and then this error message:
<= '* OK The Microsoft Exchange IMAP4 service is ready. [cgdsfDFgBvAGfsdsgQALgB....]'
=> 'A0 CAPABILITY'
<= '* CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2 SASL-IR UIDPLUS ID UNSELECT CHILDREN IDLE NAMESPACE LITERAL+'
<= 'A0 OK CAPABILITY completed.'
=> 'A1 LOGIN "<email>" "<password>"'
<= 'A1 NO LOGIN failed.'
Error: LOGIN failed.
I'm quite sure the credentials I'm using are correct, as I'm able to login my Microsoft account in a browser using them, so I'm a bit stuck on what the issue actually is.
Any help would be appreciated.
I am using nodemailer to send emails to user with office 365 account email and password are all correct but every time i am getting error - Authentication unsuccessful
Error: Invalid login:Authentication unsuccessful[BL0PR01CA0033.prod.exchangelabs.com]
code: 'EAUTH',
response: '535 5.7.3 Authentication unsuccessful [BL0PR01CA0033.prod.exchangelabs.com]',
response Code: 535,
command: 'AUTH LOGIN'**
You have to enable SMTP login for the O365 mail box or user in the admin settings
Go to Mail Settings
Turn On Authenticated SMTP
once that is done use
var transport = nodemailer.createTransport({
service: "Outlook365",
auth: {
user: 'O365email',
pass: 'O365password'
},
});
var mailOptions = {
from: 'o365email',
to: 'exaple#gmail.com', // list of receivers
subject: "Password reset requested for your account", // Subject line
text: 'reset password',
html: "<h1>Mail Testing</h1>" // html body
};
transport.sendMail(mailOptions, function(error, response){
if(error){
resp.status(500);
resp.send(error);
}else{
resp.send({message:'done'});
}
});
I have faced the same problem and after a lot of research and following few document. I came to this solution that
As an Office365 (now Microsoft365) customer I need to go to portal.azure.com, then "Manage", "Properties" and set "Manage Security defaults" to "no". I think this is messed up, but it works.
https://learn.microsoft.com/en-us/azure/active-directory/fundamentals/concept-fundamentals-security-defaults
https://github.com/nodemailer/nodemailer/issues/1071
Here is the setting what I am using
host: "domain.com",
port: 587,
secure: false,
auth: {
user: "email#domain.com",
pass: "password"
},
tls: { ciphers: 'SSLv3' },
service: "Outlook365",
The easy way to fix this is here: https://learn.microsoft.com/en-us/exchange/clients-and-mobile-in-exchange-online/authenticated-client-smtp-submission#use-the-microsoft-365-admin-center-to-enable-or-disable-smtp-auth-on-specific-mailboxes
Under the title: Use the Microsoft 365 admin center to enable or disable SMTP AUTH on specific mailboxes
You need to enable SMTP AUTH for the email you are adding creds for.
In my case, I logged on to my outlook email account and changed the POP settings to let devices and apps use POP, I also verified my account.
Everything worked well afterward.
I am sending emails using nodemailer using node.js and i have this configuration to send emails
var transporter = nodemailer.createTransport({
service: 'gmail',
host: 'smtp.gmail.com',
auth: {
user: 'myemail#gmail.com',
pass: 'password'
}
});
const mailOptions = {
from: 'myemail#gmail.com', // sender address
to: user.company_email, // list of receivers
subject: 'EnStream New Account Signup Password', // Subject line
html: `<p style="font-size : 15px;">Please sing in to your en-stream account here http://demo.en-stream.com/auth/login with this password : ${userPassword}</p>`// plain text body
};
It's sending emails on local environment correctly but in production environment on Aws Ec2 it is throwing this error
code: "EAUTH"
command: "AUTH PLAIN"
response: "534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbua↵534-5.7.14 qup7zOOL4GtmYEf1HEHBASSSBgbuMNJRQqK2v3X9mcxDRX1SrXU2Y_LSqZm7Y7yJvH2PwL↵534-5.7.14 JZW6iSXxsRhBdntFAAamrvitpdKS_YJiE-pEnXWakITAz1PAzwDMxjJPKntQrLl2Qx-xA1↵534-5.7.14 zZ4aTvKvYOAk85YHwABnnd0wHU2HkUeHPoDYqgXUWgSA_8Rrn4xkIsUN> Please log↵534-5.7.14 in via your web browser and then try again.↵534-5.7.14 Learn more at↵534 5.7.14 https://support.google.com/mail/answer/78754 a11sm34494120wrx.5 - gsmtp"
responseCode: 534
I allowed outbound port 465 in my ec2 instance security group like this
What's the real issue in this?
You may require permission for this from Gmail.
For which you have to enable the Allow access to your Google Account.
Steps:
Go to this link through the same browser from which you are trying
to Login.
It will ask "Allow access to your Google Account". Click on "Continue" button.
The message "Account access enabled" will be displayed.
Also, setting for "Less Secure Apps" must be allowed. Go through this link: https://myaccount.google.com/lesssecureapps.
If the issue still persists, check if your server IP is blocked by Gmail.
This should help!
I have spent couple of days implementing my own mail server using node.js. I used modules like "smtp-server" for creating smtp server and also "smtp-connection" to connect and send mail to it. But I'm getting confused because I don't know how to send mails from my smtp server to providers smtp servers like google or yahoo.
Can anyone help me?
Here is my code for more information:
My index.js file:
var SMTPServer = require('smtp-server').SMTPServer;
var port = 9025;
var serverOptions = {
name: "smtp-interceptor",
onConnect: onConnect,
onAuth: onAuth,
onData: onData
};
var server = new SMTPServer(serverOptions);
server.listen(port, 'localhost', function () {
console.log('SMTP server is listening on port ' + port);
});
function onConnect(session, callback) {
console.log('Connected');
return callback(); // Accept the connection
}
function onData(stream, session, callback) {
stream.pipe(process.stdout); // print message to console
console.log('Session \n', session.envelope);
stream.on('end', callback);
}
function onAuth(auth, session, callback){
if(auth.username !== 'Mahan' || auth.password !== 'Tafreshi') {
return callback(new Error('Invalid username or password'));
}
callback(null, {user: 123}); // where 123 is the user id or similar property
}
And my connection.js file:
var SMTPConnection = require('smtp-connection');
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
var connection = new SMTPConnection({
host: 'localhost',
port: 9025,
secure: false
});
connection.connect(function (){
console.log('Connceted to SMTP server');
var auth = {
user: 'Mahan',
pass: 'Tafreshi'
};
connection.login(auth, function (err) {
if(err)
return console.log('Login Failed \n', err);
console.log('Login Successful');
var envelope = {
from: "testapp#testapplocal.com",
to: "mahantp19#gmail.com"
};
var message = 'Test message1';
connection.send(envelope, message, function (err, info) {
if(err)
return console.log('Error : ' + err);
console.log('Message sent');
console.log('Accepted : ' + info.accepted);
console.log('Rejected : ' + info.rejected);
console.log(info.response);
connection.quit();
console.log('Quit connection');
connection.close();
});
});
});
There are many checks an email must pass before it's accepted by most mail providers. These checks attempt to validate the server sending the message is authorized to send on behalf of the sender.
IE: My server can send an email saying it's from "someone-special#somewhere-important.com"... That doesn't mean I'm "anywhere important" by any means.
While you may have had success sending mail from an SMTP server in the past using another technology such as PHP or an Exchange Server, the rules have changed significantly. Gmail has just began full enforcement this year.
I would assume your current issue has nothing to do with node as much as recent changes by the big providers.
Some of the checks that are needed include:
DKIM Keys (DNS Record)
SPF Record (DNS Record)
DMARK has been setup.
Dedicated IP Address for the server is required.
Your servers IP not being blacklisted.
The content of your email passes their filters.
Attempt to have an email sent from your server appear to be from a visitor or customer.
Among many others.
Any domain you want to "Act as Sender" must have these in place for most of the major providers to accept you message.
Google has a great set of tools and walkthroughs on getting an IP/Domain setup.
Visit the Google MX Record Checker and enter in the domain/subdomain you want to use as sender and it will tell you everything that is failing as well as passing.
Alternative Solutions
I use sendgrid.com. They have A node library that makes sending mail very easy. They also provide me the ability to proxy messages via SMTP. This means you can utilize the standard methods to deliver messages. You will just change out "localhost" with an hostname they provide. However, if this is for a new setup, go for the API.
Whomever is hosting your email should offer the ability for you send messages via SMTP or an API
An endless supply of other providers are out their, most of which allow low volume senders to send for FREE.
Word of warning
I tried for a few years keeping up with all the changes and inevitably, I continued to hit barriers of blocked messages with no ability to know until someone did not get an email. If your sending low volume, you should be able to use third parties without paying paying for it. If you are sending high volume, the cost of their service is cheap compared to the endless issues you will encounter even once you get it initially rolling.
PS. I have no affiliation with any email provider or sender. I pay them too.
I can't quite figure this out one... I have a SMTP server that's hosted on the same network as me, I can ping it and attempt to send emails, but the actual email never comes through. I'm using node_mailer... During the callback no error is returned... There is no authentication on the server as it's only used internally, and I'm not sure if that's maybe part of the problem. It works via ASP, but I'd like to get it working with Node.js
My script is basically just this:
email.send({
host : "theaddressoftheserver(can ping)",
port : "25",
domain : "theaddressoftheserver(can ping)",
to : "Some#internalEmail.com",
from : "Some#internalEmail.com",
subject : "Test",
body: "Test"
},
function(err, result){
if(err) console.log(err);
else console.log("Appears to have sent...");
});
I would recommend you to use Postmark.
Postmark helps small and large web applications deliver and track transactional email. Stop worrying about setup, delivery, and server maintenance. We already excel at this.
There are already two Postmark libraries for Node.js.
Postmark.js by Chris Williams
node-postmark by David Pitman
Example
var postmark = require("postmark")("YOURAPIKEY");
postmark.send({
"From": "donotreply#example.com",
"To": "target#example.us",
"Subject": "Test",
"TextBody": "Test Message"
});
I recently answered a similar question, it might help you:
https://stackoverflow.com/a/12623787/340736
Unfortunately, it's kind of hard to know exactly where your problem lies. Is the ASP-script on the same server? Have you tried running telnet against the server and sending it manually? Do the Node process have firewall restrictions?
One thing that comes to mind is that if you say that your ASP-script works, and that your SMTP-server uses no authentication. But could it be that is is, and that it is impersonating your user (the user in which the ASP-process is running under) and authenticating with that (AD authentication)..
Just a wild guess.
I figured node_mailer to send emails from a gmail account. I used code,
const transporter = createTransport({
service: gmail,
auth: {
user: process.env.MAILADDRESS,
pass: process.env.MAILPASSWORD
}
});
let mailOptions = {
from: process.env.MAILADDRESS,
to: recipient#email.com,
subject: 'verification code for verify email',
text: 'verification code
}
transporter.sendMail(mailOptions, function(err, info){
if (err) {
// something
} else {
// something
}
})
This is simple. In order to make this work I had to make sure Gmail account's Less secure app access on before using that email. I'm talking about the email that I user to send email. (Sender's email).
So my point is if there is any security option in your SMTP server that's hosted on your same network, you need to turn it off in order to node_mailer to use email address.