Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails ActionMailer "Pretty Name" Prevents Send

I'm trying to send out emails that display as from "My Name" rather than "[email protected]"

In my 'User_Mailer' class I have the line:

default :from => "[email protected]"

With that everything works perfectly. I change it to any of the below however and it never reaches the recipient.

default :from => "Name <[email protected]>"
default :from => '"Name" <[email protected]>'
default :from => "\"Name\" <[email protected]>"

... the list goes on.

What exactly should the syntax for that line be? I feel like I've tried everything.

like image 256
Charlie Egan Avatar asked Sep 26 '13 21:09

Charlie Egan


2 Answers

I don't know if something got lost in transcription, but while the first alternative may or may not be fine, the second two aren't even valid Ruby syntax.

In any event, if you look at Rails ActionMailer - format sender and recipient name/email address, the accepted answer implies that you need to quote the "name" part of the address within the string, as in '"Name" <[email protected]>'

However, a highly upvoted answer at https://stackoverflow.com/a/8106387/1008891, suggests that the inner quotes are not necessary and your first alternative format is perfectly fine.

I couldn't find anything in the ActionMailer documentation.

like image 115
Peter Alfvin Avatar answered Oct 19 '22 23:10

Peter Alfvin


Your last attempt is very close, you just need to escape the closing " around the name.

default :from => "\"Name\" <[email protected]>"
like image 25
Jeremy Green Avatar answered Oct 20 '22 01:10

Jeremy Green