I use Nodemailer with a gmail account and I would like to change the sender name. But I don't find how to do. The sender name is actually my email address, but I prefer to have "Consultation". This is my code:
var smtpTransport = mailer.createTransport("SMTP", {
service: "Gmail",
auth: {
user: "m***@gmail.com",
pass: "****"
}},
{from: 'Consultation'}
);
module.exports = {
sendNewUserEmail: function (user) {
var mail = {
from: "Consultation",
to: "i***@gmail.com",
subject: `Consultation: New client ${user.firstname} ${user.lastname}`,
html: `<h1>New client for kitomba</h1>
<ul>
<li>Firstname: ${user.firstname}</li>
<li>Lastname: ${user.lastname}</li>
<li>Phone: ${user.phone}</li>
<li>Mail: ${user.mail}</li>
<li>Address: ${user.address}</li>
<li>Suburb: ${user.suburb}</li>
<li>State: ${user.state}</li>
<li>Postal code: ${user.postalcode}</li>
</ul>`
}
smtpTransport.sendMail(mail, function (error, response) {
if (error) {
console.log("Error");
console.log(error);
} else {
console.log("Mail send!")
}
smtpTransport.close();
});
}}
Could you help me please ? Thanks in advance
According to https://nodemailer.com/message/addresses/ you can write:
from: {
name: 'Consultation',
address: 'm***@gmail.com'
}
With this, you do not need to worry about the formatting of the name you provide
Try to send it like below
let from = `Consultation <i***@gmail.com>`
var mail = {
from: from,
to: "i***@gmail.com",
subject: `Consultation: New client ${user.firstname} ${user.lastname}`,
html: `<h1>New client for kitomba</h1>
<ul>
<li>Firstname: ${user.firstname}</li>
<li>Lastname: ${user.lastname}</li>
<li>Phone: ${user.phone}</li>
<li>Mail: ${user.mail}</li>
<li>Address: ${user.address}</li>
<li>Suburb: ${user.suburb}</li>
<li>State: ${user.state}</li>
<li>Postal code: ${user.postalcode}</li>
</ul>`
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With