简体   繁体   中英

How to designate sender Name in Action Mailer

In Gmail, the following email address

class UserMailer < ActionMailer::Base
  default from: 'no-reply@example.com'
end

Turns into this (the second item)

在此处输入图片说明

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?= <mailing@sumall.com>

Any idea how to manage this with Action Mailer?

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 <some-email@example.com>" - this should work as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM