Authentication problem with nodemailer and outlook365 [duplicate] - javascript

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.

Related

Using nodejs-imap to connect to Office365 outlook email server results in Error: NO LOGIN failed

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.

How are platforms such as mailchimp able to send emails from my account?

I am working on a small service that allows users to send emails in a similar fashion to mailchimp.
How is mailchimp able to send an email from my account without asking me for my password but by simply sending me a confirmation email?
I was wondering if it was possible to replicate this effect using something like nodemailer?
Previously I wrote some code
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'test#gmail.com',
pass: 'APP_PASS'
}
});
var mailOptions = {
from: 'test2#gmail.com',
to: 'recipent#gmail.com',
subject: 'Sending Email using Node.js',
text: 'That was easy!'
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
I was hoping that the "from" part would say for example "test2#gmail.com" but it didn't, for understandable reason.
How do I prompt a user to giving my app access to sending emails from there account or on behalf of their account and then put it into nodemailer, or if nodemailer can not handle this, what could be a similar approach?

Unable to send emails using nodemailer without authentication

I need to send emails from my application for any exceptions, so I am using nodemailer for that but I cannot provide username and password for the account and without which It is not letting me send any emails. Any solutions? This is how my code looks as of now:
import nodemailer from 'nodemailer';
//Create reusable transport object using the SMTP transport
let transporter = nodemailer.createTransport({
host: 'smtp-mail.outlook.com',
port: 587,
secureConnection: false,
requireTLS: true,
tls: {
// do not fail on invalid certs
rejectUnauthorized: false
}
});
module.exports = function sendEmail(to, subject, message) {
let mailOptions = {
from: '********',
to,
subject,
html: message
};
transporter.sendMail(mailOptions, function(error) {
if (error) {
console.log(error);
}
});
};
I don't quite know about nodemailer, but with sendmail, you can send emails without a SMTP server, but for that to work you have to use dkim authentication, for short your email must be sent from the same domain as the email you're trying to send, take a look at this article, hope that helps.

nodemailer is causing an error in production environment on Aws Ec2

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!

Nodemailer connection timeout error

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
}

Categories