0

I'm a beginning programmer, and I have just implemented Mailboxer in my Ruby on Rails 4 web app. Everything is working great, but I want to have the recipients be the user's names, not their emails. I've searched for hours and can't find a precise answer. Here is my code, though it's pretty much exactly what the documentation instructs to do.

config/initializers/mailboxer.rb

    Mailboxer.setup do |config|

  #Configures if you application uses or not email sending for Notifications and Messages
  config.uses_emails = true

  #Configures the default from for emails sent for Messages and Notifications
  config.default_from = "no-reply@mailboxer.com"

  #Configures the methods needed by mailboxer
  config.email_method = :mailboxer_email
  config.name_method = :name

  #Configures if you use or not a search engine and which one you are using
  #Supported engines: [:solr,:sphinx]
  config.search_enabled = false
  config.search_engine = :solr

  #Configures maximum length of the message subject and body
  config.subject_max_length = 255
  config.body_max_length = 32000
end

app/models/user.rb

  acts_as_messageable

  ...

  def name
    email
  end

  def mailboxer_email(object)
    email
  end

Any help would be greatly appreciated. I've tried playing around with the code but I just can't quite get to the right combination of tweaks. Thank you so much!

AlenaMcLucas
  • 5
  • 1
  • 2

1 Answers1

0

This is basically a feature of the receiving mail user agent, which takes a mail header

To: somebody <me@example.com>

and displays only "somebody". One way to build that header should be

def mailboxer_email(object)
    "#{name} <#{email}>"
end

if the variable name contains the username you want the mail user agent to display.

Ulrich Thomas Gabor
  • 6,584
  • 4
  • 27
  • 41