how to implement smtp relay using nodemailer in nodejs - javascript

i am trying to implement smtp relay . host is host: "10.50.40.4", and port is 26. I am using node mailer but i dont get any email. It just gives time our error. please help how to implement it in node js .
this is my code.
var transporter = nodemailer.createTransport({
// host: "10.50.40.4",
// port: 26,
// secure: true, // use SSL
host: "10.50.40.4",
port: 26,
logger: true,
auth: {
user: "****",
pass: "***",
},
});```

Related

Unable to send email nodemailer / office365

Im unable to use nodemailer to send emails through office365 using following code:
var transporter = nodemailer.createTransport({
host: 'smtp.office365.com',
port: '587',
auth: {
user: 'user#domain.com',
pass: 'userpassword',
},
});
I have tried with different flags for nodemailer but nothing works:
secureConnection: false,
port: 587,
tls: {
ciphers:'SSLv3'
I have setup app-password in office 365 and can send email with following pyhton code:
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
username = "user#domain.com"
password = "userpassword"
mail_from = "email#email.com"
mail_to = "email#email.com"
mail_subject = "Test Subject"
mail_body = "This is a test message"
mimemsg = MIMEMultipart()
mimemsg['From']=mail_from
mimemsg['To']=mail_to
mimemsg['Subject']=mail_subject
mimemsg.attach(MIMEText(mail_body, 'plain'))
connection = smtplib.SMTP(host='smtp.office365.com', port=587)
connection.starttls()
connection.login(username,password)
connection.send_message(mimemsg)
connection.quit()
You can also use the "Outlook365" service of Nodemailer, which sets up the connection options for you.
Example
let transporter = nodemailer.createTransport({
service: 'Outlook365', // no need to set host or port etc.
auth: {
user: 'account.email#example.com',
pass: 'smtp-password'
}
});
Check the Nodemailer services

Error routines:ssl3_get_record:wrong version number in NodeJS

I make sending email with nodemailer library, I am using email office. I already success send email but but it goes to spam email and untrust. can anyone help me?
const mailTransporter = nodemailer.createTransport({
auth: {
user: email_user,
pass: email_pass,
},
host: 'mail.***.co.id',
port: 587,
secure: true,
});

why cant i send emails using nodemailer and nodejs?

I'm trying to send email using node.js and nodemailer but when I'm pressing the submit button its just loading and loading and in the end gives me a "504 Gateway Timeout Error" in the server, and "page is not working" locally.
I'm using the following code:
app.post("/postmail", function (req, res) {
var transporter = nodemailer.createTransport({
host: "smtp.mailtrap.io",
port: 2525,
secure: false,
debug: true,
auth: {
user: "xxx",
password: "xxx",
},
});
var message = {
from: "a#b", // Sender address
to: "b#c", // List of recipients
subject: "Design Your Model S | Tesla", // Subject line
text: "Have the most fun you can in a car. Get your Tesla today!", // Plain text body
};
transporter.sendMail(message, function (err, info) {
if (err) {
console.log(err);
} else {
console.log(info);
res.render("landing");
}
});
});
I must also mention that, I tried multiple smtp servers with multiple ports and configuration.
does someone know what to do?
thanks
cuase all of the smtp providers use tls/ssl for secuirity reasons. try to use secure configuration:
var transporter = nodemailer.createTransport({
host: 'smtp.mailtrap.io',
port: 465,
secure: true,
debug: true,
auth: {
user: 'xxx',
password: 'xxx'
}
});

nodemailer not working on either localhost or cloud?

Iam tryin to use nodemailer to send mails using both my local system as well as on the heroku app but in both case iam getting timeout here is my code , now i have tried using both gmail as well as smtp email but still nothing works
exports.sendMail=function(req,res)
{
if(req.METHOD=="POST")
{
var email=req.body.email;
var name=req.body.name;
var phone=req.body.phone;
var content=`
<ul>
<p>You have New Enquiry</p>
<h3>Contact Details</h3>
<ul>
<li>Email:email</li>
<li>Name:name</li>
<li>Phone:phone</li>
</ul>
`;
let transporter=nodemailer.createTransport({
host:'chi-node30.websitehostserver.net ',
port:465,
secure:true,
auth:
{
user:'chiragunplugged#chiragunplugged.com',
pass:'foo123'
},
tls:{
rejectUnauthorized:false
}
});
let mailOptions={
from:'<chiragunplugged#chiragunplugged.com',
to:'atul.11192#gmail.com',
subject:'Enquiry from datadock',
text:'you have got enquiry',
html:content
};
transporter.sendMail(mailOptions,(err,info)=>{
if(err){
res.render('final.ejs',{message:err});
return console.log(err);
}
var success="message sent";
res.render('final.ejs',{message:success});
});
}
};
please go through the code and let me know what changes I can make to get this working.
It's likely there your not actually running an SMTP server on either Heroku or from localhost, nodemailer does not do this for you. You can use googles free smtp server as detailed here https://www.digitalocean.com/community/tutorials/how-to-use-google-s-smtp-server Which will transport your mail.
let transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true, // true for 465, false for other ports
auth: {
user: account.user, // generated ethereal user
pass: account.pass // generated ethereal password
}
});
Change your transporter to the above and also provide gmail login details, then providing you have the same details inside your mail options it will show up from chiragunplugged#chiragunplugged.com as described in the options.
In the localhost its not working because a secure and safetly connection is required for sending an email but using gmail[smtp(simple mail transfer protocol)] we can achieve it functionality.
Don't forget to first do the setting - Allow less secure apps to access account.
its given permission for access gmail account.
by default this settings is off and you simply turn it on. Now move on coding part.
//////////////////////----------------------------------------------------------------////////////////////////////////////
const nodemailer = require('nodemailer');
let transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 587,
secure: false,
requireTLS: true,
auth: {
user: 'your.gmail.account#gmail.com', // like : abc#gmail.com
pass: 'your.gmailpassword' // like : pass#123
}
});
let mailOptions = {
from: 'your.gmail.account#gmail.com',
to: 'receivers.email#domain.com',
subject: 'Check Mail',
text: 'Its working node mailer'
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log(error.message);
}
console.log('success');
});

connect ECONNREFUSED AdonisJs Mail

I just started to use the Adonisjs framework and I try to send an fake email over Mailtrap. The problem is I run always into the Error connect ECONNREFUSED 52.202.164.124:2525.
Env:
MAIL_CONNECTION=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_USERNAME=ebe8f4522c4fcc
MAIL_PASSWORD=0bb7b98785dab1
config/mail.js:
connection: Env.get('MAIL_CONNECTION', 'smtp'),
/*
|--------------------------------------------------------------------------
| SMTP
|--------------------------------------------------------------------------
|
| Here we define configuration for sending emails via SMTP.
|
*/
smtp: {
driver: 'smtp',
pool: true,
port: 2525,
host: Env.get('MAIL_HOST'),
secure: false,
auth: {
user: Env.get('MAIL_USERNAME'),
pass: Env.get('MAIL_PASSWORD')
},
maxConnections: 5,
maxMessages: 100,
rateLimit: 10
},
Controller:
await Mail.send('authentication.emails.confirm_email', user.toJSON(), message => {
message.to(user.email)
.from('hello#adonisjs.com')
.subject('Please confirm your email address')
})
Adonisjs Error, Code 500
Maybe somebody can help me :)
I changed the port to 25 and it works now.
I still don't know the reason why I couldn't get a connection bevore.
It may be the firewall.
change the value to MAIL_PORT=25

Categories

Resources