我们如何在Rails Mailer中设置电子邮件发件人的名称?

THp*_*ubs 29 ruby-on-rails ruby-on-rails-4 mandrill

每当我通过我的Rails应用程序发送电子邮件时,在我的收件箱中,发件人的名称显示为"admin"..电子邮件是admin @ ...显示域的第一部分.我使用Mandrill发送电子邮件.我该如何更改此名称?

mem*_*per 57

如果您正在使用ActionMailer,请尝试以下操作

mail(
  from: 'Sender Name <sender@example.com>', 
  to: 'Receiver Name <receiver@example.com>', 
  subject: 'Subject'
)
Run Code Online (Sandbox Code Playgroud)

如果您使用的是Mandrill API,则可以显式设置发件人名称API调用有效负载


小智 9

这项工作对我来说(Rails):

default(

   from: "SenderName <hola@udocz.com>",
   reply_to: "SenderName <hola@udocz.com>"

)

def send_mail(email, subject)

   #body = ......

   mail(to: email, subject: subject, body: body, content_type: "text/html")

end
Run Code Online (Sandbox Code Playgroud)


inm*_*ean 5

我已经使用了ActionMailer 指南中的这个解决方案,它运行得很好。

class AdminMailer < ApplicationMailer
    default from: email_address_with_name('admin@example.com', 'Admin Name')
end
Run Code Online (Sandbox Code Playgroud)