Search code examples
node.jsmailgun

How to add a comma to a Mailgun from field for outbound emails?


I am using the mailgun npm package put out by mailgun.

I would like the from field to have a comma when displaying the "name" in the users email.

Excited, User <[email protected]> but its turns into User <[email protected]>

The from name in the email is User instead of Excited, User

Below is my code: (notice the comma in the from field)

mg.messages.create('sandbox-123.mailgun.org', {
    from: "Excited, User <[email protected]>",
    to: ["[email protected]"],
    subject: "Hello",
    text: "Testing some Mailgun awesomness!"
    html: "<h1>Testing some Mailgun awesomness!</h1>"
  })
  .then(msg => console.log(msg)) // logs response data 
  .catch(err => console.log(err)); // logs any error 

Solution

  • Wrap the name portion of the address in double quotes, like this:

    from: '"Excited, User" <[email protected]>',

    Here's the site I'm using for reference: http://mailformat.dan.info/headers/from.html