Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 633
Abram Avatar asked Oct 20 '25 02:10

Abram


1 Answers

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.

like image 125
CDub Avatar answered Oct 21 '25 17:10

CDub



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!