17

I'm trying to send out emails that display as from "My Name" rather than "my@email.com"

In my 'User_Mailer' class I have the line:

default :from => "me@email.com"

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

default :from => "Name <me@email.com>"
default :from => '"Name" <me@email.com>'
default :from => "\"Name\" <me@email.com>"

... the list goes on.

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

Charlie Egan
  • 4,878
  • 6
  • 33
  • 48

3 Answers3

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" <me@email.com>'

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.

Community
  • 1
  • 1
Peter Alfvin
  • 28,599
  • 8
  • 68
  • 106
  • 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" '` 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.) – Charlie Egan Sep 27 '13 at 07: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\" "` – Automatico May 29 '15 at 01:31
7

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

default :from => "\"Name\" <me@email.com>"
Jeremy Green
  • 8,547
  • 1
  • 29
  • 33
  • 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. – Charlie Egan Sep 27 '13 at 07:17
0

My code as below and it works fine

default from: "name<me@email.com>"

note:

  • there is no whitespace following name

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

chad
  • 61
  • 5