Reputation: 2856
I am sending emails from NodeJS using Nodemailer and sestransport on AWS, and am wondering how I can change the 'from name'?
fFr example, for from I put
const mailOptions =
{
from: '<[email protected]>',
to: '[email protected]',
subject: 'Hi',
}
When I get the email, it appears to come from 'noreply'. I would like to be able to change to name to anything, for example 'tom hanks', but still have the reply address [email protected]. Is that possible?
Upvotes: 5
Views: 3139
Reputation: 20354
You can specify Address object with name
and address
properties. name
property will be friendly-name for the sender, and address
field will be the actual sender email.
const mailOptions = {
from: { name: 'Naruto Uzumaki', address: '[email protected]' },
to: '[email protected]',
subject: 'Hi',
}
Upvotes: 2
Reputation: 21
If you don't want to hard code your name you can use template string
const mailOptions =
{
from: `${myNameVariable} <[email protected]>`,
to: mySenderVariable,
subject: mySubjectVariable
}
Upvotes: 0
Reputation: 2856
my bad, i just found out how. just do
const mailOptions =
{
from: 'Tom Hanks <[email protected]>',
to: '[email protected]',
subject: 'Hi',
}
and then the sender name appears as Tom Hanks
Upvotes: 2
Reputation: 2161
Simply specify it before the email address:
const mailOptions =
{
from: '"Tom Hanks" <[email protected]>',
to: '[email protected]',
subject: 'Hi',
}
Upvotes: 6