Timeout error on using nodemailer with cpanel custom email - node.js

I have created a custom email in my cpanel dashboard, so I can be sending emails with my domain name. I was using google before with nodemailer it works out well, but now trying to do it with my domain host all i get is connection timeout, i don't really know where the problem is from, but my mail host is up and running.
this question may have similar duplicates but i have gone through them but no help..
my records for the host, I don't know if the TTL and record type is causing it
TTL: 14400
record-type : CNAME
var smtpTransport = nodemailer.createTransport({
host: 'mail.mydomain.com',
port: 465,
secure: true,
auth: {
user: 'me#mydomain.com',
pass: process.env.Password
}
});
var mailOptions = {
to: somebody#gmail.com,
from: 'me#mydomain.com',
subject: 'welcome',
html: '<p>Hello this is a notification </p>',
};
smtpTransport.sendMail(mailOptions, function(err, sent){
if(err){
console.log(err)
} else {
console.log('message sent')
}
});
{ Error: Connection timeout
at SMTPConnection._formatError (/home/ubuntu/workspace/bitcoin.1/main/node_modules/nodemailer/lib/smtp-connection/index.js:591:19)
at SMTPConnection._onError (/home/ubuntu/workspace/bitcoin.1/main/node_modules/nodemailer/lib/smtp-connection/index.js:564:20)
at Timeout._connectionTimeout.setTimeout (/home/ubuntu/workspace/bitcoin.1/main/node_modules/nodemailer/lib/smtp-connection/index.js:256:18)
at ontimeout (timers.js:386:11)
at tryOnTimeout (timers.js:250:5)
at Timer.listOnTimeout (timers.js:214:5) code: 'ETIMEDOUT', command: 'CONN' }
Any help is highly appreciated :)

Related

could not setup dkim in nodemailer

I want to setup DKIM in nodemailer. Without DKIM, tls and "secure: true" my code works fine however, when I run code changed for DKIM it shows error:
Code:
var nodemailer = require('nodemailer');
var fs = require("fs");
const pr_key = fs.readFileSync("private.key", {encoding: "utf-8"})
const transporter = nodemailer.createTransport({
port: 465, // Postfix uses port 25
host: 'example.com',
secureConnection: false,
tls: {
ciphers:'SSLv3'
// rejectUnauthorized: false
},
secure: true,
dkim: {
domainName: "mail.example.com",
keySelector: "mail",
privateKey: pr_key
},
auth: {
user: "abc",
pass: "def"
},
});
var message = {
from: 'noreply#example.com',
to: 'pleasereply#example.com',
subject: 'Confirm Email',
text: 'Please confirm your email',
html: '<p>Please confirm your email</p>'
};
transporter.sendMail(message, (error, info) => {
if (error) {
return console.log(error);
}
console.log('Message sent: %s', info.messageId);
});
Error Message:
[Error: 7336:error:1408F10B:SSL routines:ssl3_get_record:wrong version
number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:332: ] {
library: 'SSL routines', function: 'ssl3_get_record', reason:
'wrong version number', code: 'ESOCKET', command: 'CONN' }
I have already configured TXT record for DKIM in DNS and SMTP server running on my server side is programed using library "smtp-server" module of nodejs.
What I tried:
I tried changing port to 25, 2525, 465 and 143
Tried every combination of host, domainname for domain "example.com" and tried keySelector "mail" and "#".
I tried commenting "secureConnection" and "tls: {}" and then changing to "secure: false" which results in other error:
Error: self signed certificate
at TLSSocket.onConnectSecure (node:_tls_wrap:1530:34)
at TLSSocket.emit (node:events:526:28)
at TLSSocket._finishInit (node:_tls_wrap:944:8)
at TLSWrap.ssl.onhandshakedone (node:_tls_wrap:725:12) { code: 'ESOCKET', command: 'CONN' }
i tried to change "to:" property of message object to my gmail account just for testing but still got same message saying I got wrong version
Help me resolving this issue.

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.

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

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 :).

Connection timeout error when sending mail from Zohomail using Nodemailer

Below is my Node app.js code. With these settings, I am receiving a connection timeout error. Any idea what I am missing here?
var nodemailer = require("nodemailer");
var transporter = nodemailer.createTransport({
host: 'smtp.zoho.com',
port: 465,
secure: true, // use SSL
auth: {
user: '<myemail#example.com>',
pass: '<myemailpassword>'
}
});
var mailOptions = {
from: "<fromemail#example.com>",
to: "<toemail#example.com>",
subject: "Hello",
generateTextFromHTML: true,
html: { path: './tmpl.html' }
};
transporter.sendMail(mailOptions, function(error, response) {
if (error) {
console.log(error);
} else {
console.log(response);
}
transporter.close();
});
Error shown
{ Error: Connection timeout
at SMTPConnection._formatError (/home/ubuntu/workspace/mailapp/node_modules/nodemailer/lib/smtp-connection/index.js:557:19)
at SMTPConnection._onError (/home/ubuntu/workspace/mailapp/node_modules/nodemailer/lib/smtp-connection/index.js:530:20)
at Timeout._connectionTimeout.setTimeout (/home/ubuntu/workspace/mailapp/node_modules/nodemailer/lib/smtp-connection/index.js:248:18)
at ontimeout (timers.js:380:14)
at tryOnTimeout (timers.js:244:5)
at Timer.listOnTimeout (timers.js:214:5) code: 'ETIMEDOUT', command: 'CONN' }
Can anyone please help me?
Some cloud providers disable ports like 465 and 587, try using port 2525 instead of 465.
Update
Since you're using Cloud9 for this I found out they have blocked all outbound smtp calls from their servers. If you need to send anyways you need to choose another cloud provider or use one of their recommended services.
https://community.c9.io/t/how-can-i-send-email-from-my-app/1262

How to send mail with nodemailer (node.js) by direct method?

I try to write simple mailer just to send some text (for testing purposes) with nodemailer. If I understood well it may sent a mail by smtp or direct. At first I want to sent with DIRECT method.
The next code very simple:
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({direct:true,
host: 'smtp.yandex.ru',
port: 465,
auth: {
user: 'login#yandex.ru',
pass: 'password' },
secure: true
});
var mailOptions = {
from: 'nworksheet#gmail.com',
to: 'sky-bell#mail.ru',
subject: 'Hello',
text: 'This is auto mail sending'
};
transporter.sendMail(mailOptions, function (error, info) {
if(error) {
return console.log(error);
}
console.log("Message sent "+info.response)
});
But I have the next error:
{ Error: Sending failed
at QueryReqWrap.asyncCallback [as callback] (dns.js:65:16)
at QueryReqWrap.onresolve [as oncomplete] (dns.js:216:10)
errors:
[ { Error: queryMx ENOTFOUND mail.ru
at errnoException (dns.js:28:10)
at QueryReqWrap.onresolve [as oncomplete] (dns.js:216:19)
code: 'ENOTFOUND',
errno: 'ENOTFOUND',
syscall: 'queryMx',
hostname: 'mail.ru' } ] }
What does it mean? How to fix it? Node not see 'mail.ru'? Why?
The best way to achieve this is
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
service: 'Yandex',
auth: {
user: 'your_yandex_email',
pass: 'your_password_for_email' },
});
var mailOptions = {
from: 'your_yandex_email',
to: 'sky-bell#mail.ru',
subject: 'Hello',
text: 'This is auto mail sending'
};
transporter.sendMail(mailOptions, function (error, info) {
if(error) {
return console.log(error);
}
console.log("Message sent "+info.response)
});
Whenever you specify the service command, it automatically sets the port and secures the email.
Also remember to put and fetch the credentials from a config file.
Looks like it can't find an MX record for mail.ru. It seems to exist however. https://toolbox.googleapps.com/apps/dig/#MX/mail.ru
Does this machine have DNS set up properly? Can you dig it from that machine?

Resources