const smtpConfig = {
host: smtpHost,
port: smtpPort,
secure: false
};
const transporter = nodemailer.createTransport(smtpConfig);
const mailOptions = {
from: sender, // sender address
to: receivers, // list of receivers
subject: 'Hello', // Subject line
text: 'Hello world?', // plain text body
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);
});
When i try to run this piece of code, i get the following error
Unexpected socket close
at Timeout.setTimeout (C:\Users\abhatia\Documents\slnSubtrees.cd\mdm-updater\node_modules\nodemailer\lib\smtp-transport\index.js:188:31)
at ontimeout (timers.js:386:14)
at Timer.unrefdHandle (timers.js:492:5)
Error is from https://github.com/nodemailer/nodemailer/blob/master/lib/smtp-transport/index.js#L187-L188
// still have not returned, this means we have an unexpected connection close
let err = new Error('Unexpected socket close');
It means returned = true
never executed from either send
or error
events.
Make sure your mailOptions
are correct and you are able to connect.
Probably invalid smtp configuration or a firewall issue or problems with antiviruses blocking email connections. Try to debug the tcp connection to see what happens there.
it should be secure:true. it worked for me. refer the below code
const smtpConfig = {
host: smtpHost,
port: smtpPort,
secure: true
};
I am having the same issue Error: Unexpected socket close
at Timeout.setTimeout
I am trying to send an email from the contact form with the attachments. If no file is upload to the form or file size is small, the email is sent perfectly. But if I try to send over 10MB file in slow network speed, it throws the following error:
Error: Unexpected socket close
at Timeout.setTimeout [as _onTimeout] (E:\PATH TO\node_modules\nodemailer\lib\smtp-transport\index.js:188:31)
at ontimeout (timers.js:458:11)
at Timer.unrefdHandle (timers.js:570:5) ---------------------
undefined
(node:17364) UnhandledPromiseRejectionWarning: Error: Unexpected socket close
at Timeout.setTimeout [as _onTimeout] (E:\PATH TO\node_modules\nodemailer\lib\smtp-transport\index.js:188:31)
at ontimeout (timers.js:458:11)
at Timer.unrefdHandle (timers.js:570:5)
(node:17364) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise
which was not handled with .catch(). (rejection id: 1)
(node:17364) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero
exit code.
Although the app is crashed with the above error, sometimes the email with the attachment is still sent. the flowing error is shown on the browser:
This page isn’t working
localhost didn’t send any data.
ERR_EMPTY_RESPONSE
The code snippet is as below:
let transporter = nodemailer.createTransport({
host: 'sip2-267.nexcess.net',
port: 587,
secure: false,
auth: {
user: '[email protected]',
pass: '**'
}
});
let mailOptions = {
from: `"Web Form - " <${formData.email}>`,
to: '[email protected]', // list of receivers
subject: `${formData.subject} - Order #${formData.orderNumber}`,
// text: `${formData.message}`, // plain text body
html: `
<div>Contact # : ${formData.contactNumber}</div>
<div>Order #: ${formData.orderNumber}</div>
<p><b>Message:</b></p>
<p>${formData.message}</p>
<div>${formData.firstName} ${formData.lastName}</div>
`// End html body
};
Thank you in advance.
hey,
just set secure:true
const smtpConfig = {
host: smtpHost,
port: smtpPort,
secure: true
};
On Mon, Jul 2, 2018 at 7:56 AM, Prem Acharya notifications@github.com
wrote:
I am having the same issue Error:
Unexpected socket close at Timeout.setTimeoutI am trying to send an email from the contact form with the attachments.
If no file is upload to the form or file size is small, the email is sent
perfectly. But if I try to send over 10MB file in slow network speed, it
throws the following error:Error: Unexpected socket close
at Timeout.setTimeout [as _onTimeout] (E:\PATH TO\node_modules\nodemailer\
lib\smtp-transport\index.js:188:31)
at ontimeout (timers.js:458:11)
at Timer.unrefdHandle (timers.js:570:5) ---------------------
undefined
(node:17364) UnhandledPromiseRejectionWarning: Error: Unexpected socket
close
at Timeout.setTimeout [as _onTimeout] (E:\PATH TO\node_modules\nodemailer\
lib\smtp-transport\index.js:188:31)
at ontimeout (timers.js:458:11)
at Timer.unrefdHandle (timers.js:570:5)
(node:17364) UnhandledPromiseRejectionWarning: Unhandled promise
rejection. This error originated either by throwing inside of an async
function without a catch block, or by rejecting a promise
which was not handled with .catch(). (rejection id: 1)
(node:17364) [DEP0018] DeprecationWarning: Unhandled promise rejections
are deprecated. In the future, promise rejections that are not handled will
terminate the Node.js process with a non-zero
exit code.Although the app is crashed with the above error, sometimes the email with
the attachment is still sent. the flowing error is shown on the browser:
This page isn’t working
localhost didn’t send any data.
ERR_EMPTY_RESPONSEThe code snippet is as below:
let transporter = nodemailer.createTransport({
host: 'sip2-267.nexcess.net',
port: 587,
secure: false,
auth: {
user: '[email protected]',
pass: '**'
}
});let mailOptions = { from: `"Web Form - " <${formData.email}>`, to: '[email protected]', // list of receivers subject: `${formData.subject} - Order #${formData.orderNumber}`, // text: `${formData.message}`, // plain text body html: ` <div>Contact # : ${formData.contactNumber}</div> <div>Order #: ${formData.orderNumber}</div> <p><b>Message:</b></p> <p>${formData.message}</p> <div>${formData.firstName} ${formData.lastName}</div> `// End html body };
Thank you in advance.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/nodemailer/nodemailer/issues/830#issuecomment-401654825,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AhuR2M0juuHt5_DKEKiaeOBgMnL73Sz1ks5uCYTRgaJpZM4RWwpV
.
--
Thanks and Regards,
Anshul Shah
Assosciate software Engineer
https://www.brainvire.com/
https://twitter.com/Brainvire
https://www.linkedin.com/company/brainvire-infotech-pvt-ltd
https://www.brainvire.com/blog/ https://www.facebook.com/Brainvire
https://plus.google.com/+Brainvire/posts
https://www.youtube.com/user/Brainvire +91 8735000077
+91-7990932686 / EXTN: 5020
anshul.[email protected]
www.brainvire.com https://www.brainvire.com/
This e-mail may contain confidential and/or privileged information. If you
are not the intended recipient (or have received this e-mail in error)
Please notify the sender immediately and destroy this email. Any
unauthorized copying, disclosure or distribution of the material in these
e-mails is strictly forbidden.
Think before you print
Thanks for prompt response @anshul757,
I got the following error after changing secure: true:::
Error: connect ETIMEDOUT 209.126.23.99:465
at Object._errnoException (util.js:1003:13)
at _exceptionWithHostPort (util.js:1024:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1195:14)
errno: 'ETIMEDOUT',
code: 'ECONNECTION',
syscall: 'connect',
address: '209.126.23.99',
port: 465,
command: 'CONN'
Thanks you.
I am getting the same response when secure: true. Were you able to come up with any solutions?
Most helpful comment
hey,
just set secure:true
const smtpConfig = {
host: smtpHost,
port: smtpPort,
secure: true
};
On Mon, Jul 2, 2018 at 7:56 AM, Prem Acharya notifications@github.com
wrote:
--
Thanks and Regards,
Anshul Shah
Assosciate software Engineer
https://www.brainvire.com/
https://twitter.com/Brainvire
https://www.linkedin.com/company/brainvire-infotech-pvt-ltd
https://www.brainvire.com/blog/ https://www.facebook.com/Brainvire
https://plus.google.com/+Brainvire/posts
https://www.youtube.com/user/Brainvire +91 8735000077
+91-7990932686 / EXTN: 5020
anshul.[email protected]
www.brainvire.com https://www.brainvire.com/
This e-mail may contain confidential and/or privileged information. If you
are not the intended recipient (or have received this e-mail in error)
Please notify the sender immediately and destroy this email. Any
unauthorized copying, disclosure or distribution of the material in these
e-mails is strictly forbidden.
Think before you print