THpubs
THpubs

Reputation: 8162

How can we set the name of the email sender in Rails Mailer?

Whenever I send an email through my Rails app, in my inbox, the name of the sender is shown as "admin".. The email is admin@... The first part of the domain is shown. Im using Mandrill to send the email. How can I change this name?

Upvotes: 50

Views: 24323

Answers (3)

inmydelorean
inmydelorean

Reputation: 518

I've used this solution from the ActionMailer guide and it works perfectly.

class AdminMailer < ApplicationMailer
    default from: email_address_with_name('[email protected]', 'Admin Name')
end

Upvotes: 7

membLoper
membLoper

Reputation: 2002

If you're using ActionMailer, try below

mail(
  from: 'Sender Name <[email protected]>', 
  to: 'Receiver Name <[email protected]>', 
  subject: 'Subject'
)

If you're using the Mandrill API, you can explicitly set the sender name API call payload

Upvotes: 100

Ricardo Garcia Izasiga
Ricardo Garcia Izasiga

Reputation: 201

This work for me(Rails):

default(

   from: "SenderName <[email protected]>",
   reply_to: "SenderName <[email protected]>"

)

def send_mail(email, subject)

   #body = ......

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

end

Upvotes: 20

Related Questions