nodemailer and zoho email issue '530 Must issue a STARTTLS command first.' - node.js

I am using the latest version of nodemailer version 4.1.0. I tried using the sample code available here
https://nodemailer.com/smtp/
Here is my code
let transporter = nodemailer.createTransport({
host: 'smtp.zoho.com',
port:587,
secure: false,
auth: {
user: this.user,
pass: this.password
}
});
var mailOptions: nodemailer.SendMailOptions = {
from: ****#***.com,
to: test#abc.com,
subject: 'Hello ✔',
text: 'Hello world ✔',
html: '<b>Hello world ✔</b>'
};
transporter
.sendMail(mailOptions)
.then(
(info) => {
// console.log(info);
resolve({status: info.messageId})
}
)
.catch(err => {
// console.log(err);
reject({status: err.toString()})
})
I get the following error. I have set the secure flag as false, and have also used ignodeTLS. The previous version of nodemailer 0.7.1 did not have any issues. Am I missing out on any specific configuration?
{ Error: Invalid login: 530 Must issue a STARTTLS command first.
at SMTPConnection._formatError
(C:\Project\NotificationService\node_modules\nodemailer\lib\smtp-connection\index.js:577:19)
at SMTPConnection._actionAUTHComplete (C:\Project\NotificationService\node_modules\nodemailer\lib\smtp-connection\index.js:1306:34)
at SMTPConnection._responseActions.push.str (C:\Project\NotificationService\node_modules\nodemailer\lib\smtp-connection\index.js:349:26)
at SMTPConnection._processResponse (C:\Project\NotificationService\node_modules\nodemailer\lib\smtp-connection\index.js:733:20)
at SMTPConnection._onData (C:\Project\NotificationService\node_modules\nodemailer\lib\smtp-connection\index.js:529:14)
at Socket._socket.on.chunk (C:\Project\NotificationService\node_modules\nodemailer\lib\smtp-connection\index.js:481:47)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at TCP.onread (net.js:548:20)
code: 'EAUTH',
response: '530 Must issue a STARTTLS command first.',
responseCode: 530,
command: 'AUTH PLAIN' }

you can also use this without these tls parameter default value is false.
you got the error because of you don't pass service:'zoho' in nodemailer
let transporter = nodemailer.createTransport({
service:'Zoho',
host: this.service,
port:587,
secure: false,
auth: {
user: this.user,
pass: this.password
}
});

After going through the typings( "#types/nodemailer") file I added the following flags
1) service :'Zoho'
2) requireTLS :false
it is working now :)
let transporter = nodemailer.createTransport({
service:'Zoho',
host: this.service,
port:587,
secure: false,
ignoreTLS:true,
requireTLS:false,
auth: {
user: this.user,
pass: this.password
}
});

In the year 2022, I got this on the official documentation https://nodemailer.com/smtp/well-known/
let transporter = nodemailer.createTransport({
service: 'SendPulse', // no need to set host or port etc.
auth: {
user: 'account.email#example.com',
pass: 'smtp-password'
}
});
transporter.sendMail(...)
So, for Zoho just simply:
let transporter = nodemailer.createTransport({
service: 'Zoho', // no need to set host or port etc.
auth: {
user: 'account.email#example.com',
pass: 'smtp-password'
}
});
transporter.sendMail(...)
Just test it and works. I believe it doesn't need to put any setting if we use "Well-known services"
Hope this helps someone drop by in this thread :).

Related

NodeMailer keeps timing out

I'm building my first node project and I'm trying to send mails to users using nodemailer and OAuth2.0. It did work last night but suddenly started timing out this morning no matter what, it runs for a few minutes and then times out without sending the mail.
This is my code so far
const nodemailer = require("nodemailer");
const sendEmail = async (email, subject, text) => {
try {
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
type: 'OAuth2',
user: process.env.MAIL_USERNAME,
pass: process.env.MAIL_PASSWORD,
clientId: process.env.OAUTH_CLIENTID,
clientSecret: process.env.OAUTH_CLIENT_SECRET,
refreshToken: process.env.OAUTH_REFRESH_TOKEN
}
});
await transporter.sendMail({
from: 'user#gmail.com',
to: email,
subject: subject,
text: text,
});
console.log("email sent sucessfully");
} catch (error) {
console.log(error, "email not sent");
}
};
and I'm calling the function this way await sendEmail(email, "Password reset", link)
I get this error message after a few minutes
Error: connect ETIMEDOUT 173.194.76.108:465
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1187:16) {
errno: -60,
code: 'ESOCKET',
syscall: 'connect',
address: '173.194.76.108',
port: 465,
command: 'CONN'
} email not sent
I would appreciate any help as I'm really frustrated already
I fixed this by adding this to the transporter object
host: 'smtp.gmail.com',
port: 587,
secure: false,

I got error when i try to send mail with nodemailer and i'm using cpanel information

const nodemailer = require("nodemailer");
require("dotenv").config();
const smtpTransport = nodemailer.createTransport({
host: "mail.ibendouma.com",
port: 465,
secure: true,
auth: {
user: process.env.USER,
pass: process.env.SECRET,
},
});
async function run() {
let sendResult = await smtpTransport
.sendMail({
from: "'iBendouma' <service#ibendouma.com>",
to: "tipox1254#gmail.com",
subject: "Hello from iBendouma",
text: "copier le code et verifier votre identité",
})
.then((res) => console.log(res))
.catch((err) => console.log(err));
console.log(sendResult);
}
run().catch((error) => console.log(error));
Error: Missing credentials for "PLAIN"
at SMTPConnection._formatError (C:\Users\msypro\Desktop\test\node_modules\nodemailer\lib\smtp-connection\index.js:787:19)
at SMTPConnection.login (C:\Users\msypro\Desktop\test\node_modules\nodemailer\lib\smtp-connection\index.js:441:38)
at C:\Users\msypro\Desktop\test\node_modules\nodemailer\lib\smtp-transport\index.js:272:32
at SMTPConnection. (C:\Users\msypro\Desktop\test\node_modules\nodemailer\lib\smtp-connection\index.js:211:17)
at Object.onceWrapper (events.js:519:28)
at SMTPConnection.emit (events.js:400:28)
at SMTPConnection._actionEHLO (C:\Users\msypro\Desktop\test\node_modules\nodemailer\lib\smtp-connection\index.js:1322:14)
at SMTPConnection._processResponse (C:\Users\msypro\Desktop\test\node_modules\nodemailer\lib\smtp-connection\index.js:950:20)
at SMTPConnection._onData (C:\Users\msypro\Desktop\test\node_modules\nodemailer\lib\smtp-connection\index.js:752:14)
at TLSSocket.SMTPConnection._onSocketData (C:\Users\msypro\Desktop\test\node_modules\nodemailer\lib
msypro#Msypro MINGW64 ~/Desktop/test (master)
$ node app.js
Error: Missing credentials for "PLAIN"
at SMTPConnection._formatError (C:\Users\msypro\Desktop\test\node_modules\nodemailer\lib\smtp-connection\index.js:787:19)
at SMTPConnection.login (C:\Users\msypro\Desktop\test\node_modules\nodemailer\lib\smtp-connection\index.js:441:38)
at C:\Users\msypro\Desktop\test\node_modules\nodemailer\lib\smtp-transport\index.js:272:32
at SMTPConnection. (C:\Users\msypro\Desktop\test\node_modules\nodemailer\lib\smtp-connection\index.js:211:17)
at Object.onceWrapper (events.js:519:28)
at SMTPConnection.emit (events.js:400:28)
at SMTPConnection._actionEHLO (C:\Users\msypro\Desktop\test\node_modules\nodemailer\lib\smtp-connection\index.js:1322:14)
at SMTPConnection._processResponse (C:\Users\msypro\Desktop\test\node_modules\nodemailer\lib\smtp-connection\index.js:950:20)
at SMTPConnection._onData (C:\Users\msypro\Desktop\test\node_modules\nodemailer\lib\smtp-connection\index.js:752:14)
at TLSSocket.SMTPConnection._onSocketData (C:\Users\msypro\Desktop\test\node_modules\nodemailer\lib\smtp-connection\index.js:191:44) {
code: 'EAUTH',
command: 'API'
}
undefined
This error Error: Missing credentials for "PLAIN" at SMTPConnection._formatError occurs when your credentials are missing. First thing you can do is to check whether the env file is specified properly in the code. You have to make sure that your index.js or server.js (or the name of your nodemailer code file) is in the same directory as env file.
If the above is all correct then try adding quotes around your env variable like below.
auth: {
user: `${process.env.USER}`,
pass: `${process.env.SECRET}`,
},
Your auth field have to look like this.
auth: {
user: "someone#gmail.com",
pass: "somesecretpass",
},
Hope this worked!

Using Webmail with Nodemailer

I used gmail with node mailer to create a login system in js node.
In development mode I used gmail.
const sendEmail = async options =>{
//1)Create a transporter
// const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: process.env.EMAIL_SEND_SESSION,
pass: process.env.EMAIL_SEND_PASSWORD,
}
});
//2) Define the mail options
const mailOptions = {
from:'Creative Point <test764#gmail.com>',
to:options.email,
subject:options.subject,
html:options.message
}
//3) Actually send the email
await transporter.sendMail(mailOptions);
};
But in production mode I would like to use webmail,I received when I created the data and port account on cpanel.
const transporter = nodemailer.createTransport({
service:'smtp.specialsoft.ro ',
port: 465,
auth: {
user: process.env.EMAIL_SEND_SESSIONCPANEL,
pass: process.env.EMAIL_SEND_PASSWORDCPANEL,
}
});
But it gives me the next mistake.
Error: There was an error sending the email.Try again later!Error: Invalid login: 535-5.7.8 Username
and Password not accepted. Learn more at
535 5.7.8 https://support.google.com/mail/?p=BadCredentials g20sm3266545ejz.88 - gsmtp
at C:\Users\Cosmin\Desktop\Authentification System Node
JS,Express,JsonWebToken\controllers\sessionController.js:56:21
at processTicksAndRejections (internal/process/task_queues.js:93:5)
I haven't found anything relevant on the internet about this error.
I solved the problem by following the steps below.
I installed a module: nodemailer-smtp-transport.
const smtpTransport = require('nodemailer-smtp-transport');
I corrected the host name and some options.
host:'mail.mydomani.ro'
secureConnection: false,
tls: {
rejectUnauthorized: false
}
3)I integrated the module nodemailer-smtp-transport in the transporter.
const transporter = nodemailer.createTransport(smtpTransport({
host:'mail.mydomanin.ro',
secureConnection: false,
tls: {
rejectUnauthorized: false
},
port: 587,
auth: {
user: process.env.EMAIL_SEND_SESSION,
pass: process.env.EMAIL_SEND_PASSWORD,
}
}));

nodemailer and gmail APIs

Im trying to get nodemailer working using Google GMail API.
I've got my Google project set up - using their oauth sandbox for redirect,
I've got a clientID, secret and refresh token from my developers console.
The Code
const nodemailer = require('nodemailer');
const xoauth2 = require('xoauth2');
// create reusable transporter
let transporter = nodemailer.createTransport( {
service: 'gmail',
xoauth2: xoauth2.createXOAuth2Generator({
user: 'me#myDomain.com',
clientid: 'blahblahblah.apps.googleusercontent.com',
clientSecret: 'k33p-gUeSsINg',
refreshToken: '123BritneyIsTheBest'
}),
tls: {
rejectUnauthorized: false
}
} );
// setup email data
let mailOptions = {
from: 'me#myDomain.com',
to: 'me#yahoo.com',
subject: 'Hello there Google API...',
text: 'Hello Google API',
html: '<b>Hello Google API</b>'
};
// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log(error);
}
console.log('Message sent: ', info.messageId);
});
The Error.
{
Error: Mail command failed: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1 https://support.google.com/mail/?p=WantAuthError l24sm4075119ywk.21 - gsmtp
at SMTPConnection._formatError (C:\abc\index.js:591:19)
at SMTPConnection._actionMAIL (C:\abc\index.js:1350:34)
at SMTPConnection._responseActions.push.str (C:\abc\index.js:840:18)
at SMTPConnection._processResponse (C:\abc\index.js:747:20)
at SMTPConnection._onData (C:\abc\index.js:543:14)
at TLSSocket._socket.on.chunk (C:\abc\index.js:495:47)
at emitOne (events.js:116:13)
at TLSSocket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
code: 'EENVELOPE',
response: '530-5.5.1 Authentication Required. Learn more at\n530 5.5.1 https://support.google.com/mail/?p=WantAuthError l24sm4075119ywk.21 - gsmtp',
responseCode: 530,
command: 'MAIL FROM'
}
I have tried this - and it works, but it's my understanding that this is very unsecured and NOT acceptable for production.
const nodemailer = require('nodemailer');
// create reusable transporter object
let transporter = nodemailer.createTransport( {
host: 'smtp.gmail.com',
port: 587,
secure: false,
auth: {
user: 'me#myDomain.com',
pass: 'Seriously?'
}
});
... all the rest is the same, removed for brevity...
The existing posts solutions have not helped.
Thank You
How about this modification?
From :
let transporter = nodemailer.createTransport( {
service: 'gmail',
xoauth2: xoauth2.createXOAuth2Generator({
user: 'me#myDomain.com',
clientid: 'blahblahblah.apps.googleusercontent.com',
clientSecret: 'k33p-gUeSsINg',
refreshToken: '123BritneyIsTheBest'
}),
tls: {
rejectUnauthorized: false
}
} );
To :
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
type: 'oauth2',
user: 'me#myDomain.com',
clientId: 'blahblahblah.apps.googleusercontent.com', // This key is "clientId".
clientSecret: 'k33p-gUeSsINg',
refreshToken: '123BritneyIsTheBest'
},
tls: {
rejectUnauthorized: false
}
});
Note :
Please confirm whether https://mail.google.com/ was included in the scope, when you retrieved the refresh token.
Please confirm whether gmail API is enabled.
It may be required to turn on "Allow less secure apps: ON" at https://myaccount.google.com/lesssecureapps.
Reference :
nodemailer OAuth2
In my environment, I confirmed that this works fine. But if this was not useful for you, I'm sorry.

Error 535 while setting up nodemailer with GoDaddy

I'm wondering if anyone has figured out how to use GoDaddy hosted email with nodemailer. I have an email submission box from my contact form, and it triggers the following script:
function sendEmail ( to, subject, body ) {
var transporter = nodemailer.createTransport({
service: 'Godaddy',
host: "relay-hosting.secureserver.net",
port: 465,
secureConnection: true,
auth: {
user: 'email#godaddydomain.com',
pass: 'password'
}
});
var mailOptions = {
from: 'email#godaddydomain.com',
to: to,
subject: subject,
text: body
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
}
I've tried a few different options, and made sure my ports are all open, but I'm having a hard time with the authentication. I keep getting errors like this:
{ Error: Invalid login: 535 Authentication Failed for email#godaddydomain.com. User does not have any relays assigned.
at SMTPConnection._formatError (/var/www/node/node_modules/nodemailer/lib/smtp-connection/index.js:577:19)
at SMTPConnection._actionAUTHComplete (/var/www/node/node_modules/nodemailer/lib/smtp-connection/index.js:1306:34)
at SMTPConnection._responseActions.push.str (/var/www/node/node_modules/nodemailer/lib/smtp-connection/index.js:349:26)
at SMTPConnection._processResponse (/var/www/node/node_modules/nodemailer/lib/smtp-connection/index.js:733:20)
at SMTPConnection._onData (/var/www/node/node_modules/nodemailer/lib/smtp-connection/index.js:529:14)
at Socket._socket.on.chunk (/var/www/node/node_modules/nodemailer/lib/smtp-connection/index.js:481:47)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at TCP.onread (net.js:547:20)
code: 'EAUTH',
response: '535 Authentication Failed for email#godaddydomain.com. User does not have any relays assigned.',
responseCode: 535,
command: 'AUTH PLAIN' }
Any thoughts or suggestions would be really appreciated.
It seems like this error is related to the hostname. Try this one:
var transporter2 = nodemailer.createTransport({
service: 'Godaddy',
host: "smtpout.secureserver.net",
secureConnection: true,
port: 465
})
I was facing the same error. I changed configuration to the following:
var transporter = nodemailer.createTransport({
host: "smtpout.secureserver.net",
secure: true,
secureConnection: false, // TLS requires secureConnection to be false
tls: {
ciphers: "SSLv3",
},
requireTLS: true,
port: 465,
debug: true,
auth: {
user: "xxxx#yyyy.com",
pass: "pass",
},
});
It worked like a charm for me.
In case anyone's still looking for this (as I have been the last few days!), I found all the server information GoDaddy was suggesting was completely wrong. Found the answer in cPanel - if you go to the main bit, and click on 'Email Accounts', on your account it should have an option on the right saying 'Connect Devices'. Click on that and it'll give you the correct server and port information for what you need, which for me ended up being this:
var transporter = nodemailer.createTransport({
host: "sxb1plzcpnl487525.prod.sxb1.secureserver.net",
secure: true,
secureConnection: true,
port: 465,
auth: {user: "yourcpanelusername#yourdomain.com", pass: "yourcpanelpassword"},
tls: {rejectUnauthorized: false}
});
Took me forever to find that specific weird server it needed. Hope this helps. Apologies for formatting, it's my first post here but I wanted to help as I've spent days on this now.

Resources