I am trying to implement Nodemailer for sending one or bulk emails but facing trouble to handle when there is a failure in sending email for eg. Email Address not found. I need a list of these bounced emails and other such failures and insert them into the DB,after trying to send the email twice.
Below is my code:
const nodemailer = require("nodemailer");
var smtpConfig = nodemailer.createTransport(
{
host: hostname,
port: port,
secure: false,
auth: {
user: username,
pass: password
},
logger: false,
debug: false
},
{
headers: [],
priority: "normal"
}
);
function sendMailnew() {
const mailOptions = {
from: "email.com,
to: "sjdhf#jhdf.com",
subject: "my testing emails new",
html: "my testing email",
dsn: {
id: "123",
return: "HEADERS",
notify: ["failure", "delay"],
recipient: "abc#gmail.com"
}
};
smtpConfig.sendMail(mailOptions, function(error, response) {
if (error) {
console.log(error);
} else {
console.log("mail sent");
}
});
}
sendMailnew();
I am using gmail SMTP. Please Help.Thanks!Let me know if any more details are needed.
Related
I am trying to send emails to using nodemailer from my site but it gives me this error
Error: Invalid login: 535-5.7.8 Username and Password not accepted.
and I made sure the password and credentials is accurate. This is my code for setting up nodemailer
function message(merchantEmail, msgTxt){
var transporter = nodemailer.createTransport({
host: "smtp.gmail.com",
secure: true,
port: 465,
auth: {
user: 'kesterdaniel401#gmail.com',
pass: process.env.PASSWORD
},
tls: {
rejectUnauthorized: false
}
});
var mailOptions = {
from: 'kesterdaniel401#gmail.com',
to: merchantEmail,
subject: 'Sending Email using Node.js',
text: msgTxt
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
}
module.exports = message
This is where I called the function
message(productOwner.Email, `You have received an order from ${Buyer.Name} for the product ${product. ProductName}. Please contact the customer as soon as possible. Customer Number is ${Buyer.PhoneNumber}.`)
I gonna to create SMTP Server to send, receiving E-mails, using nodemailer
I have a custom domain from namecheap to do this
tried use this code but i don't receive any email on my Gmail account
const nodemailer = require('nodemailer');
const { SMTPServer } = require("smtp-server")
const server = new SMTPServer({
onData(stream, session, callback) {
console.log('test')
},
disabledCommands: ['AUTH'],
secure: false
});
server.listen(25)
const transporter = nodemailer.createTransport({
host: '192.168.1.2',
port: 25,
secure: false,
auth: {
user: '',
pass: ''
},
tls: {
rejectUnauthorized: false
}
});
transporter.sendMail({ from: "support#myDomain.com", to: "myGmail#gmail.com", text: "text", subject: "subject" })
.then(info => {
console.log(info)
}).catch(err => {
console.log(err)
})
log error:
test
Error: Message failed: 421 Timeout - closing connection
There any method to create smtp server using node js for send, receiving E-mails?
I'm using nodemailer to send email validations with no success, I get no errors when sending the e-mail, it actually says the e-mail was sent but I recieve nothing.
I tried sending e-mails using this e-mail (with gmail integration) and it works fine.
This is my config
import Mailer from "nodemailer";
async function sendEmail(emailData) {
const SMTP = process.env.EMAIL_SMTP;
const SENDER = Mailer.createTransport({
host: SMTP,
port: 465,
secure: true,
auth: {
user: process.env.EMAIL_SENDER,
pass: process.env.EMAIL_SENDER_PASSWORD
},
tls: {
ignoreTLS: true
}
});
const RECEIVER = {
from: process.env.EMAIL_SENDER,
to: emailData.to,
subject: emailData.subject,
text: emailData.text,
};
SENDER.sendMail(RECEIVER, function (error) {
if (error) {
console.log(error);
} else {
console.log("E-mail sent"); // E-mail sent is fired at console
}
});
await SENDER.verify(function (err, success) {
console.log({ err, success }); // {err: null, success: true}
})
}
I'm trying to send this using local env, does this work locally or the SMTP should match my domain?
I am using nodemailer to send email using nodejs. Here is my code
export function createOrder(req, res) {
var transporter = nodemailer.createTransport({
service: 'gmail',
secure: false,
port: 25,
auth: {
user: 'fahadsubzwari924#gmail.com',
pass: 'Jumpshare1'
},
tls: {
rejectUnauthorized: false
}
});
var mailOptions = {
from: 'Fahad <fahadsubzwari924#gmail.com>',
to: 'shan4usmani#hotmail.com',
subject: 'Order Status ',
text: 'Your order has finished'
}
transporter.sendMail(mailOptions, function (err, res) {
if (res) {
console.log(res);
res.json({
message: res,
status: 200
})
} else {
console.log(err, 'Error');
}
})
}
When i am trying to send email then email is sending successfully but request is going on pending for a long time which is shown in network section of chrome.
How can i get rid of this request pending issue?
I'm trying to build an app that sends an email when something is triggered.
I'm not getting any errors, but getting no emails to my inbox.
This is the code:
SMTP:
var SMTPServer = require('smtp-server').SMTPServer;
var server = new SMTPServer({
secure: false, authOptional: true
});
server.listen(465);
emailjs:
var email = require('emailjs');
var emailServer = email.server.connect({
host: 'localhost',
port: 465,
ssl: false
});
emailServer.send({
text: 'Hey howdy',
from: 'NodeJS',
to: 'Wilson <person#gmail.com>',
cc: '',
subject: 'Greetings'
}, function (err, message) {
console.log(err || message);
});
The output I see on my console is:
{ attachments: [],
alternative: null,
header:
{ 'message-id': '<1470995427701.0.2864#DESKTOP-M85CNRC>',
date: 'Fri, 12 Aug 2016 12:50:27 +0300',
from: '=?UTF-8?Q?NodeJS?= <>',
to: '=?UTF-8?Q?Wilson?= <person#gmail.com>',
cc: '',
subject: '=?UTF-8?Q?Greetings?=' },
content: 'text/plain; charset=utf-8',
text: 'Hey howdy' }
Any idea about what's missing?
Thanks
i am using nodemailer-smtp-transport and is working perfectly for me, follow is my configuration inside the function through which i am sending mail. Hope this may help.
var nodemailer = require('nodemailer'),
smtpTransport = require("nodemailer-smtp-transport");
//configuration
var transporter = nodemailer.createTransport(smtpTransport ({
auth: {
user: user, //email of sender
pass: pass //password of sender
},
host: host, //my email host
secureConnection: true,
port: 587,
tls: {
rejectUnauthorized: false
},
}));
var mailOptions = {
from: user,
to: to,
subject: subject,
text: text
}
transporter.sendMail(mailOptions, function(error, info){
if(error){
console.log(error);
}else{
console.log("success");
}
});
In emailjs file host cannot be localhost it should be like :smtp.your-email.com.
var server = email.server.connect({
user: "username",
password:"password",
host: "smtp.your-email.com",
ssl: true
});
I use an Gmail account not very important for my tests in stead of module smtp-server.
First: Required activate the use less secure apps at your own risk as indicated in the Gmail documentation:
https://myaccount.google.com/u/2/lesssecureapps?pageId=none
After:
var email = require("emailjs");
var server = email.server.connect({
user: "YOUR_ACCOUNT#gmail.com",
password:"YOUR_PASSWORD",
host: "smtp.gmail.com",
ssl: true
});
server.send({
text: "Hello world",
from: "YOUR_NAME <YOUR_ACCOUNT#gmail.com>",
to: "FRIEND_NAME <FRIEND_ACCOUNT#gmail.com>",
subject: "Hello"
}, function(err, message) { console.log(err || message); });