17

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.

3 Answers 3

19

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.

2
  • Yes there was a typo in the question - was way too tired and at the end of my tether. I'm sure I had in fact tried '"Name" <[email protected]>' many times, I'm certain it hadn't worked. Anyway, now it seems to. Really odd, either sleep or restarting the rails server fixed it! (or maybe it was just a persistent typo.) Sep 27, 2013 at 7:12
  • This is very valuable if you want to do a name which is something like Hi @ yall! <3, then you can do "\"Hi @ yall! <3\" <[email protected]>"
    – Automatico
    May 29, 2015 at 1:31
7

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

default :from => "\"Name\" <[email protected]>"
1
  • This also seems to work! oddly also after some sleep... There was a typo in my question too - I'm sure i'd tried this. I'm not sure if sleeping on it or restarting the rails server helped but something changed. Cheers. Sep 27, 2013 at 7:17
0

My code as below and it works fine

default from: "name<[email protected]>"

note:

  • there is no whitespace following name

  • none ascii name not work, for example: chinese charactor

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.