Hello all. I want create a simple sending email. My code is:
var smtpTransposrt = nodemailer.createTransport('SMTP', {
service: 'Gmail',
auth: {
user: '[email protected]',
pass: 'mypass'
}
});
var text = 'Hello';
text = text + 'some big text here';
var mailOptions = {
from: 'max',
to: '[email protected]',
subject: 'Text',
text: 'Text sdfgsfgsdf gsdf gsdfg s',
html: text
}
app.get('/sendmail', function (req, res) {
smtpTransposrt.sendMail(mailOptions, function(error, request){
if(error){
console.log(error);
}else{
req.send('Good');
}
})
});
When I go /sendmail in consol I have a error:
{ [Error: connect ETIMEDOUT] code: 'ETIMEDOUT', errno: 'ETIMEDOUT', syscall: 'connect' }
{ [Error: socket hang up] code: 'ECONNRESET', sslError: undefined }
{ [Error: connect ETIMEDOUT] code: 'ETIMEDOUT', errno: 'ETIMEDOUT', syscall: 'connect' }
What I do wrong?
Is your server behind a proxy or is there an outbound firewall? Can you connect to the Gmail SMTP from command line:
openssl s_client -crlf -connect smtp.gmail.com:465
The last line of the output from this command should be something like this:
220 mx.google.com ESMTP w9sm15181754lbk.7 - gsmtp
smtp.gmail.com can be pretty cranky at accepting connections
Sometimes changing to using smtp.googlemail.com works better
I am also having the same error while sending mail. I am behind http proxy. Can you suggest how can i send mail using proxy.....
I had the same problem and the following worked for me:
"Gmail2":{
transport: "SMTP",
host: "smtp.gmail.com",
secureConnection: false,
port: 587,
requiresAuth: true,
domains: ["gmail.com", "googlemail.com"]
}
You might consider adding it to the wellknown services.
var smtpConfig = nodemailer.createTransport("SMTP",{
host: "smtp.gmail.com",
secureConnection: false,
port: 587,
requiresAuth: true,
domains: ["gmail.com", "googlemail.com"],
auth: {
user: "[email protected]",
pass: "mypass"
}
});
This worked for me. Its amazing
Some times it may problem:
https://support.google.com/accounts/answer/6010255?hl=en
Use this link and try to turn off less security
{ [Error: connect ETIMEDOUT 216.58.197.37:587]
code: 'ETIMEDOUT',
errno: 'ETIMEDOUT',
syscall: 'connect',
address: '216.58.197.37',
port: 587,
stage: 'init' }
hello i want to perform a simple sending emails,i m using a nodemailer ..above is the error which i m facing
and my code is
if(user.Role[0].AcessPermission == 3 || user.Role[0].AcessPermission == forgotpasswordRequest.body.sourceApp){
var smtpTransport = nodemailer.createTransport("SMTP",{
host :'smtp.googlemail.com',
auth : true,
startTLS :true,
port : 587,
auth: {
user: '*@gmail.com',
pass: '***'
}
});
in mailoption recipient address is wrong
On Tue, Feb 27, 2018 at 12:13 PM Amit Dubey notifications@github.com
wrote:
I'm having the same issue, Someone can help
Here is my code
var transporter = nodemailer.createTransport({ service: "Gmail", port: 587, auth: { user: 'myemail', pass: 'mypassword' } }); var mailOptions = { from: '[email protected]', to: 'to@gmail, subject: 'Sending Email using Node.js', text: 'That was easy!' }; transporter.sendMail(mailOptions, function(error, info){ if(error){ res.status(400); return res.json({ success:false, message:'Unable to send email', error:error }); } else { res.status(200); return res.json({ success:true, message:'Email Sent', data: info.response }); } });And here is my error
{
"code": "ECONNECTION",
"errno": "ECONNREFUSED",
"syscall": "connect",
"address": "173.194.68.108",
"port": 587,
"command": "CONN"
}—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/nodemailer/nodemailer/issues/176#issuecomment-368764397,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AKDCXititvtpJAUFkdILdqqHQzMb_vBoks5tY6QhgaJpZM4A17yN
.
Here is my working solution, You can try this
const nodemailer = require('nodemailer');
const smtpTransport = require('nodemailer-smtp-transport');
function sendEmail(to, subject, html){
nodemailer.createTestAccount((err, account) => {
var transporter = nodemailer.createTransport(smtpTransport({
host: 'hostname',
port:465,
auth: {
user: '[email protected]',
pass: 'password'
}
}));
let mailOptions = {
from: '"Admin" <[email protected]>',
to: to,
subject: subject,
html: html
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.log('Error', error);
}
else{
console.log('Success', info);
}
});
});
}
for host:'hostname', are you using smtp.gmail.com?
I'm using aws smtp server "smtp.mail.us-east-1.awsapps.com". But if you want to send mail from gmail then you have to allow less secure app from gmail setting & hostname will be same 'smtp.gmail.com'. Allow from here https://myaccount.google.com/lesssecureapps
Most helpful comment
var smtpConfig = nodemailer.createTransport("SMTP",{
host: "smtp.gmail.com",
secureConnection: false,
port: 587,
requiresAuth: true,
domains: ["gmail.com", "googlemail.com"],
auth: {
user: "[email protected]",
pass: "mypass"
}
});
This worked for me. Its amazing