Configure nodemailer to function with no-reply configured sender email account - node.js

I have the following code to send emails to my users from an account configured as a sender "noreply account, plus I added with the following forward filter":fail: No such person at this address. " into CPanel.
However I got an error with Nodemailer, so my question is how I could use a nonreply filter with nodemailer, any tricks I could do including probably changing the "from" field to show the recipients "noreply" account as the sender, while maybe able to send via another account ?
Note that sending works when I remove the filter from CPanel.
const mailTransport = nodemailer.createTransport({
host: 'mail.myserver.com',
port: 465,
secure: true, // true for 465, false for other ports
auth: {
user: 'noreply#myserver.com',
pass: smtpPassword
},
tls: {
// do not fail on invalid certs
rejectUnauthorized: false
}
});
const mailOptions = {
from: `App <noreply#myserver.com>`,//`${APP_NAME} <${REPLY_EMAIL}>`,//
to: email
};
// The user subscribed to the newsletter.
mailOptions.subject = subject
mailOptions.text = text;
return mailTransport.sendMail(mailOptions)
.then(() => console.log(log, email))
.catch(error => console.error('There was an error while sending the email:', error));
**Nodemailer error log:**
550-No such person at this address.
550 Sender verify failed
code: 'EENVELOPE',
response: '550-Verification failed for <noreply#myserver.com>\n550-No such person at this address.\n550 Sender verify failed',
responseCode: 550,
command: 'RCPT TO',

Use service : 'gmail' in the mailTransport object

Related

How to send an auto reply email with a html page as email in NodeJS

I recently started programming in NodeJS. I can't find any way how can I send an auto-reply email. When another person sends me an email, in that time an auto-reply email will be sent to his/her email, which is in HTML email format.
How can I do this?
First you need to poll or monitor your account for the incoming mail, using a generic smtp or imap client, such as https://www.npmjs.com/package/imap, or even better, a module that actually monitors new email, such as https://www.npmjs.com/package/mail-notifier
The posted example is
Start listening new mails :
const notifier = require('mail-notifier');
const imap = {
user: "yourimapuser",
password: "yourimappassword",
host: "imap.host.com",
port: 993, // imap port
tls: true,// use secure connection
tlsOptions: { rejectUnauthorized: false }
};
notifier(imap)
.on('mail', mail => console.log(mail))
.start();
Keep it running forever :
const n = notifier(imap);
n.on('end', () => n.start()) // session closed
.on('mail', mail => console.log(mail.from[0].address, mail.subject))
.start();
Next, its hard to beat nodemailer to send your response.
https://nodemailer.com/about/
Here is their example. (Half this code is comments and logs)
"use strict";
const nodemailer = require("nodemailer");
// async..await is not allowed in global scope, must use a wrapper
async function main() {
// Generate test SMTP service account from ethereal.email
// Only needed if you don't have a real mail account for testing
let testAccount = await nodemailer.createTestAccount();
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: "smtp.ethereal.email",
port: 587,
secure: false, // true for 465, false for other ports
auth: {
user: testAccount.user, // generated ethereal user
pass: testAccount.pass, // generated ethereal password
},
});
// send mail with defined transport object
let info = await transporter.sendMail({
from: '"Fred Foo 👻" <foo#example.com>', // sender address
to: "bar#example.com, baz#example.com", // list of receivers
subject: "Hello ✔", // Subject line
text: "Hello world?", // plain text body
html: "<b>Hello world?</b>", // html body
});
console.log("Message sent: %s", info.messageId);
// Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321#example.com>
// Preview only available when sending through an Ethereal account
console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
// Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
}
main().catch(console.error);

nodemailer 'From' header is missing

I got this error in my sended mail box
host gmail-smtp-in.l.google.com[74.125.195.26] said:
550-5.7.1 [23.83.209.30 11] Our system has detected that this message
is 550-5.7.1 not RFC 5322 compliant: 550-5.7.1 'From' header is missing.
550-5.7.1 To reduce the amount of spam sent to Gmail, this message has been
550-5.7.1 blocked. Please visit 550-5.7.1
https://support.google.com/mail/?p=RfcMessageNonCompliant 550 5.7.1 and
review RFC 5322 specifications for more information. d15si13788945pgv.519 -
gsmtp (in reply to end of DATA command)
here is my code, I try to send an email from hosting with nodemailer
exports.main = ()=>{
return transporter = nodemailer.createTransport({
host: "melisandre.id.rapidplex.com",
port: 465,
secure: true, // true for 465, false for other ports
auth: {
user: 'YOI AKUAKULTUR <noreply#yoiakuakultur.com>', // generated ethereal user
pass: 'xxxxxxxxx', // generated ethereal password
},
})
}
exports.register = async (nama, username, token)=>{
let transporter = await this.main();
let info = await transporter.sendMail({
from: 'YOI AKUAKULTUR <noreply#yoiakuakultur.com>', // sender address
to: username, // list of receivers
subject: "Akun anda telah diverifikasi", // Subject line
text: "Aktivasi Akun Anda", // plain text body
html: 'test email', // html body
});
transporter.sendMail(info, (err,res)=>{
if(err){
console.log(username)
};
})
}
that'is all detail I have, did you guys know how to fix it? it was okay before

this is my nodemailer program Even if i give wrong mail in TO addrress also it is showing message sent how to rectifyy that

const nodemailer = require('nodemailer');
let mailTransporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 587,
secure: false,
auth: {
user: '*************',
pass: '*********',
},
});
let mailDetails = {
from: '********',
to: 'uuwdwuvw#', //guguygugiug
subject: 'Test mail',
//text: 'redeem your gift',
html: 'redeem your coupon code ',
};
mailTransporter.sendMail(mailDetails, function (err, data) {
if (err) {
console.log('Error Occurs');
} else {
console.log('Email sent successfully');
}
});
this is my nodemailer program Even if i give wrong mail in TO addrress also it is showing message sent how to rectifyy that
Nodemailer itself can't tell if an email has been delivered or not. It can tell you only if the email has been sent. There's a difference between email being sent and being delivered. Detecting bounced emails is out of scope for the Nodemailer.
In order to do that you need to implement your own bounced email mechanism, probably with your own SMTP server. It's not an easy thing to do, so you should probably use some real email provider that has this functionality instead of Gmail (Google likes to block such applications).
Have a look at the similar question I've found on GitHub and on SO.

Zoho mail says 535 Authentication Failed in Node Js

I am creating an Application using Node Express and MongoDB. After user creation a successful mail want to send to the user. I am using zohomail and can able to use those username and password to login zohomail online. But when I try to send mail I got an error as
code: 'EAUTH',
response: '535 Authentication Failed',
responseCode: 535,
command: 'AUTH PLAIN'
This is my code
helped snippet from
if (user) {
var transporter = nodemailer.createTransport({
host: 'smtp.zoho.com',
port: 465,
secure: true, // use SSL
auth: {
user: 'sample#sample.com', //zoho username
pass: 'password' //zoho password## Heading ##
}
});
var mailOptions = {
from: 'sample#sample.com',
to: req.body.email,
subject: 'Created Successfully',
html: '<h1>Hi ' + req.body.fname + ',</h1><p>You have successfully created.</p>'
};
transporter.sendMail(mailOptions, function(error, info) {
if (error) {
console.log(error);
} else {
res.status(200).send(setting.status("User created Successfully, Please Check your Mail"))
}
});
}
Thank you Nguyen Manh Tung
As said in comment.
I had enabled 2 Factor Authentication (2FA) in Zoho mail.
So, I login my account here and go to the Two Factor Authentication and get Application specific password.
After that I used the application specific password instead of zoho mail password in Node Js.
if (user) {
var transporter = nodemailer.createTransport({
host: 'smtp.zoho.com',
port: 465,
secure: true, // use SSL
auth: {
user: 'sample#sample.com', //zoho username
pass: 'application specific password' //Not zoho mail password because of 2FA enabled
}
});
var mailOptions = {
from: 'sample#sample.com',
to: req.body.email,
subject: 'Created Successfully',
html: '<h1>Hi ' + req.body.fname + ',</h1><p>You have successfully created.</p>'
};
transporter.sendMail(mailOptions, function(error, info) {
if (error) {
console.log(error);
} else {
res.status(200).send(setting.status("User created Successfully, Please Check your Mail"))
}
});
}
1/ Check your password.
2/ Check 2 factor authentication
Did you enable 2 factor authentication with Zoho?
If you enabled it, you need to create application specific password.
If you are from India, replace smtp.zoho.com with smtp.zoho.in keeping other things same. Sample is given below:
const transporter = nodemailer.createTransport({
host: "smtp.zoho.in",
port: 465,
secure: true,
auth: {
user: process.env.ZOHO_EMAIL,
pass: process.env.ZOHO_PASSWORD,
},
});
For anyone still facing authentication errors after adding 2 Factor authentication and generating an App password. If you created your Zoho Mail account from the EU please change your host to the following:
host: "smtp.zoho.eu"

Send email without password using nodemailer over a zimbra smtp

im using nodemailer to send emails in a web app using keystonejs as cms. The web app is stored in a server and the email server in other, but SMTP communications between servers does not require password. Now, i need to send emails to other peoples when required using a generic account without the password field because is not neccesary.
This is my nodemailer config:
var selfSignedConfig = {
host: 'smtp.abc.cu',
port: 25,
secure: false, // use TLS
auth: {
user: email.email,
pass: email.password //NOT REQUIRED
},
tls: {
// do not fail on invalid certs
rejectUnauthorized: false
}
};
var transporter = nodemailer.createTransport(selfSignedConfig);
// verify connection configuration
and:
"email": {
"email": "abcde#abc.cu",
"password": ""
}
I'm stuck on this, I have tried with "password": "" and "password": " " and nothing works. The email server is Zimbra.
This gave me the following error:
*-------------------------*
The server IS NOT READY to take the messages: Error: Invalid login: 535 5.7.8 Error: authentication failed: authentication failure
*-------------------------*
Greetings...
In our case we removed tls, auth and secure fields and it worked on our SMTP server.
The from, to options were set from mail options separately.
You might give the following a try:
var nodemailer = require ('nodemailer'),
_ = require ('lodash')
var selfSignedConfig = {
host: 'smtp.abc.cu',
port: 25
};
var transporter = nodemailer.createTransport(selfSignedConfig);
var attachFiles = attachments?attachments:[];
var attachObjArray = [];
_.forEach(
attachFiles,
filePath=>attachObjArray.push({path:filePath})
);
var mailOptions = {
from: fromEmail, // sender address (who sends)
to: toEmail, // list of receivers (who receives)
subject: subject, // Subject line
html: body, // html body
attachments:attachObjArray //attachment path with file name
};
// send mail with defined transport object
transporter.sendMail(mailOptions, function(error, info) {
if(error){
return console.log(error);
} else {
console.log('Message sent: ' + info.response);
}
done();
});

Resources