Abram
Abram

Reputation: 41874

How to designate sender Name in Action Mailer

In Gmail, the following email address

class UserMailer < ActionMailer::Base
  default from: '[email protected]'
end

Turns into this (the second item)

enter image description here

Is there anyway to have the "from" address be "no-reply" but have the from name be something more meaningful?

I have noticed my email form SumAll renders as from "SumAll" but with a different reply to address as below:

From: =?utf-8?Q?SumAll?= <[email protected]>

Any idea how to manage this with Action Mailer?

Upvotes: 4

Views: 1825

Answers (1)

CDub
CDub

Reputation: 13344

Check out section 2.3.4 of the ActionMailer documentation.

Specifically:

2.3.4 Sending Email With Name

Sometimes you wish to show the name of the person instead of just their email address when they receive the email. The trick to doing that is to format the email address in the format "Full Name ".

def welcome_email(user)
  @user = user
  email_with_name = "#{@user.name} <#{@user.email}>"
  mail(to: email_with_name, subject: 'Welcome to My Awesome Site')
end

If it's the same sender for all emails in your mailer, I'd suggest trying default from: "Some name <[email protected]>" - this should work as well.

Upvotes: 7

Related Questions