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
Related
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 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")
});
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.
We are trying to create a contact form. the problem is that Node mailer's from data shows my own while I set to the persons email who sends it. Here is the code:
app.post('/api/v1/contact', (req, res) => {
var data = req.body;
var smtpTransport = nodemailer.createTransport({
service: 'Gmail',
port: 465,
auth: {
user: '',
pass: ''
}
});
var mailOptions = {
from: data.email,
to: 'myemail#domain.com',
subject: data.title,
html: `<p>${data.email}</p>
<p>${data.message}</p>`,
...
...
data.email inside the HTML tag inside email body shows correctly the email of the sender while in the from field the same data.email shows my own email. It looks like I am sending email to me. What's the problem?
That is not a bug. You simply not have access to send emails from someone else email address.
The purpose of contact form in any website to make a communication from the customer to the site owner.
You can not make customer to send email using contact page.You can respond to their email.
So I will suggest you put customer email which you are getting in req.body.email parameter so that you can get to know who is trying to make contact.
It is better to give Website admin /support email address in
auth: {
user: '',
pass: ''
}
user attribute and the password for the same in pass attribute.
It is not the issue of nodemailer.
My target is to be able to send email without setting credentials. For this purpose I've picked up the nodemailer module. Here is my code:
var nodemailer = require('nodemailer');
var message = {
from: "test#gmail.com",
to: "test1#gmail.com",
subject: "Hello ✔",
text: "Hello world ✔",
html: "<b>Hello world ✔</b>"
};
nodemailer.mail(message);
According to documentation the "direct" transport method should be used (actually I don't know nothing about transport methods at all). But unfortunately this method is absolutely unstable - sometimes it works sometimes it doesn't.
Could anyone shed some light on it? How can I send email without configuring SMTP transport credentials?
Sure, but it totally depends on server's configuration. Most email servers will not work unless you use authentication. It is 2017 🙂
Well, AFAIK nodemailer detects the correct configuration based on the email domain, in your example you have not set the transporter object so it uses the default port 25 configured. To change the port specify in options the type. And I highly recommend you to specify it explicitly.
Probably windows firewall or antivirus preventing outgoing access. Try to get debug/error messages. We need something to help you more.
Here is a new version of the nodemailer and here is an example how to use it:
const nodemailer = require('nodemailer');
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: 'smtp.example.com',
port: 465,
secure: true, // secure:true for port 465, secure:false for port 587
auth: {
user: 'username#example.com',
pass: 'userpass'
}
});
// setup email data with unicode symbols
let mailOptions = {
from: '"Fred Foo 👻" <foo#blurdybloop.com>', // sender address
to: 'bar#blurdybloop.com, baz#blurdybloop.com', // list of receivers
subject: 'Hello ✔', // Subject line
text: 'Hello world ?', // plain text body
html: '<b>Hello world ?</b>' // html body
};
// 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);
});
I hope it helps.