I cannot able to send the mail using nodejs program I used node-mailer and nodemailer smtp transport module.This program worked perfectly lastweek.but suddenly now it is not working .I tried but i cannot able to find the error.can anyone help me .Thankyou.
var nodemailer = require('nodemailer');
var smtpTransport = require('nodemailer-smtp-transport');
var transporter = nodemailer.createTransport(smtpTransport({
service: 'Gmail',
host: 'smtp.gmail.com',
port: 465,
auth: {
user: 'sampleprogrammers#gmail.com',
pass: 'ashbdhbedbudu.'
}
}));
transporter.sendMail({
from: "sampleprogrammers#gmail.com",
subject:" hello ji " ,
text: "I would like to write dialogue",
attachments:[
{
'filename':'link.txt',
'path': 'E:/STUDIES/CORE SUBJECTS/link.txt'
}
],
to: "vikirockz456#gmail.com"
}, function(error, info) {
if (error) {
return console.log(error);
}
console.log('Message %s sent: %s', info.messageId, info.response);
console.log("Mail sent successfully");
});
SEE THE ERROR BELOW:
Can you please go through this question : Nodemailer Error Can't Fix
Maybe your version of node changed knowingly or unknowingly. It seems your version of node is not compatible with nodemailer.
Related
The following code send email from server side. How to I use that code in Angular 9 application.
Could you please help some one for this.
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'test#test.com',
pass: 'xxxx'
}
});
var mailOptions = {
from: 'test#test.com',
to: 'test#test.com',
subject: 'Sending Email using Node.js',
text: `Hi, thank you for your nice Node.js Email.`
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
Probably, the above code will works i the Angular application, but the big problem doing that, is you will have exposed mail transport credentials in your front app. As mentioned before, best solution is create a simple API that send the email on server side.
i tried nodemailer but its not working. i want to send email to user through my node js website. can anyone please help me to get it done
//code
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'youremail#gmail.com',
pass: 'yourpassword'
}
});
var mailOptions = {
from: 'youremail#gmail.com',
to: 'myfriend#yahoo.com',
subject: 'Sending Email using Node.js',
text: 'That was easy!'
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
In my experience sending emails can be made a lot easier by outsourcing the work to a provider like https://www.mailgun.com, the cost is $0.0008 per email. The reason for this is not only simplicity but deliverability. So many people have sent so many fake and junk emails over the years, emails often end up in spam folders when the server is not set up correctly. Things like adding SPF records to domains can obviously help but in all honesty, I now just use a sending provider.
Try this. The port is important to be 465.
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'youremail#gmail.com',
pass: 'yourpassword'
},
port: 465,
secure: true,
tls: {
rejectUnauthorized: false
}
});
Below is the sample code am using for sending mail.
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
host: 'smtp.office365.com',
port: 587,
auth: {
user: 'me#myserver.com',
pass: 'mypassword'
}
});
var mailOptions = {
from: 'no-reply#myserver.com', //It will work if i give me#myserver.com but i need no-reply#myserver.com in from option.
to: 'someuser#gmail.com',
subject: 'Sending Email using Node.js',
text: 'That was easy!'
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
I will give me below error if i use no-reply#myserver.com in from option.
Error: Message failed: 554 5.2.0
STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied;
Failed to process message due to a permanent exception with message
Cannot submit message.
Some email servers do not accept changing FROM address. This is not about nodemailer. You need to check your email server configuration.
I keep getting this issue tls.connect is not a function.
I am using nodemailer with my Reactjs and Nextjs application.
sendmail.js?71c0a4a:33 Error: TypeError: tls.connect is not a function
at SMTPConnection.connect (index.js?49b6f52:228)
at getSocket (index.js?55ebb9c:234)
at setImmediate (index.js?55ebb9c:70)
at run (setImmediate.js?d2412a6:40)
at runIfPresent (setImmediate.js?d2412a6:69)
at onGlobalMessage (setImmediate.js?d2412a6:109)
The weird part is if I run the script in the console it will work, but running though the browser I get the tls.connect is not a function error.
const nodemailer = require('nodemailer');
let transporter = nodemailer.createTransport({
service: 'gmail',
secure: false,
port: 465,
auth: {
user: '',
pass: ''
},
});
class mail {
options (to, text, subject, html) {
console.log(to)
var mailOptions = {
from: '',
to: to,
subject: subject,
text: text,
html: html
}
return(mailOptions);
}
sendMail(mailOptions) {
console.log(mailOptions)
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.error('Error:', error);
}
console.log('Message %s sent: %s', info.messageId, info.response);
});
}
}
export default mail;
You're using nodemailer inside a bundler, on Client Side,
NodeMailer should only be used at ServerSide.
This issue is environmental and also be aware that even if that was working, you would be exposing that google account and password by using it at client side.
Consider creating a serverside nodejs api to send your emails
issue
I read the following, Sending emails in Node.js? but I'm looking for a way to send an email, not through an smtp server. As in the linux envirement you have different options such as sendmail and others
I could ofc use the environment I'm in to make use of the already existing functionality, but I would be interested to learn how one would dispatch the email using only js, if even possible..
I set up an smtp server using the smtp module: https://github.com/andris9/smtp-server why I'm interested in the delivery part of a server I already setup.
Take a look at node-mailer. You can set it up without smtp server. https://github.com/nodemailer/nodemailer
var nodemailer = require('nodemailer');
var send = require('gmail-send');
var mailserverifo = nodemailer.createTransport({
service: 'gmail',
host : "smtp.gmail.com",
port : "465",
ssl : true,
auth: {
user: 'email#gmail.com',
pass: 'password#'
}
});
var Mailinfo = {
from: 'email#gmail.com',
to: 'email#info.com',
subject: 'Testing email from node js server',
text: 'That was easy!'
};
mailserverifo.sendMail(Mailinfo, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email Send Success: ' + info.response);
}
});
Enable less secure app form setting -
https://www.google.com/settings/security/lesssecureapps
Disable Captcha -
https://accounts.google.com/b/0/displayunlockcaptcha
You can use sendmail in Node js. I'v using it and it's working fine for me.
npm install sendmail --save
const sendmail = require('sendmail')();
sendmail({
from: 'no-reply#yourdomain.com',
to: 'test#qq.com, test#sohu.com, test#163.com ',
subject: 'test sendmail',
html: 'Mail of test sendmail ',
}, function(err, reply) {
console.log(err && err.stack);
});
https://www.npmjs.com/package/sendmail
First:Install nodemailernpm install nodemailer
Then put this into your node file:
var nodemailer = require('nodemailer');
var http = require('http');
var url = require('url');
console.log("Creating Transport")
var transporter = nodemailer.createTransport({
service:'Hotmail',
auth: {
user:'salace2008765#outlook.com',
pass: 'alice123#'
}
});
var mailOptions = {
from:'salace2008765#outlook.com',
to: 'jerome20090101#gmail.com',
subject: 'This is a test: test',
text:'TgK'
}
console.log("Sending mail")
transporter.sendMail(mailOptions, function(error, info) {
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response)
}
})
It usally works
Sources:W3Schools and Nodemailer's official site