I am trying to use nodemailer using my Gmail address. It works when an email is sent to Gmail address but when I try to send mail to any Outlook address, it gets lost in the matrix. Help is appreciated. Thanks in advance.
let transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: "Mysendergmail", // generated ethereal user
pass: "password", // generated ethereal password
}
});
transporter.sendMail({
from: '"service#onlineshop" <Mysendergmail>', // sender address
to: "myoutlookreciever", // list of receivers
subject: "Hello ✔", // Subject line
text: "Hello world?", // plain text body
html: "<b>Hello world?</b>", // html body
},(err,info)=>{
if(err){
res.status(400).json(err)
}
else res.status(200).json("sent email")
});
Related
I am trying to receive email from users using nodemailer. The email will be sent from users email and received by my email. But all it doing is sending email from my email to my email though I set different email account for from and to. But when I revesre the email acounts and set from:myemail#example.com and to:usersemail#example.com this works fine. Why this is happening? How can I fix this so that I can receive emails from users? Here is the code:
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
service: "gmail",
secure: false,
auth: {
user: process.env.MY_EMAIL,
pass: process.env.MY_PASSWORD,
},
});
// Creating the email
let info = {
from: process.env.USERS_EMAIL,
to: process.env.MY_EMAIL,
subject: 'Demo message',
text: 'For clients with plaintext support only',
html: `
<p>This is a demo email</p>
`
};
//send the email
transporter.sendMail(info, function (err, info) {
if (err) {
console.log(err);
}
else{
console.log(info);
}
})
function sendmail(req,res){
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'myemail#gmail.com',
pass: 'mypassword'
}
});
const mailOptions = {
from: 'Something',
to: 'to_email',
subject: 'My subject',
html: `<button>My Button</button>`
};
transporter.sendMail(mailOptions)
}
When I send the email everything arrives without problems, however, for the email from it doesn't work, when the email I received arrives, the email from which should be Something is the email of the sender the email, so basically if I send an email to 123#outlook.com from my email 123#gmail and set the from to something when I send and the email is received , the email from is not something, but 123#gmail which is the email responsible for sending it. How can I fix this to display Something instead of the email responsible for sending
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
The email comes from my e-mail address rather than the sender. Any ideas?
var transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: 'mail',
pass: 'pass'
}
});
var mailOptions = {
from: req.body.email , // sender address
to: 'mail', // list of receivers
subject: ' ', // Subject line
text: req.body.message,
html: '<p>'+req.body.message+'</p>'// plain text body
};
This is how Gmail works. It won't let you to send emails as anyone but you, for security reasons.
If you need more flexibility then you should use a transactional email service like Mailgun, Mandrill or SendGrid - which you can easily use with Nodemailer (there are Nodemailer transports available for them, just like for Gmail).
See: https://www.npmjs.com/browse/keyword/nodemailer
how to send mail to multiple recipients which are stored in database(mongodb) using nodemailer?
Currently Im sending to single recipient. But im not able to figure out how to send mail to multiple people whose mail ids are stored in mongodb.
If someone knows the answer, please respond.
Thank you in advance :)
Use mongodb distinct to get array for all the email_address you want to send the email, and pass that array to nodemailer.
const nodemailer = require('nodemailer');
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'gmail.user#gmail.com',
pass: 'yourpass'
}
});
let email_arr = db.users.distinct( "email", { /* Any condition you want to put*/ } )
let mailOptions = {
from: "test#example.com", // sender address
subject: "Hello ✔", // Subject line
text: "Hello This is an auto generated Email for testing from node please ignore it", // plaintext body
to: email_arr
}
// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) {
if (error) {
return console.log(error);
}
console.log('Message %s sent: %s', info.messageId, info.response);
});