0

I am fighting with setting up the "from" information that is shown in the email in header.

It still shows incorrect email address. In the mailer class, I manually set the default email address:

class NotificationMailer < ActionMailer::Base
  default content_type: "text/html", :from => 'default@email.com'

I also specified this in the method for sending the email(s):

  def welcome_email(user)
    @user = user
    mail(to: @user.email, subject: "Welcome!", from: 'default@email.com')    
  end

But when I receive this email, it's from my-personal-email@gmail.com. I searched through the Rails app where is this email address set up and it's here:

config/initializers/setup_email.rb:

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
  :address => "smtp.gmail.com",
  :port => 587,
  :domain => "logistadvise.com",
  :user_name => "my-personal-email@gmail.com",
  :password => "mypassword",
  :authentication => "plain",
  :enable_starttls_auto => true
}

Emails are sent out well, but worries me that I am unable to properly set the "from" header.

How to do that?

Thank you.

user984621
  • 46,344
  • 73
  • 224
  • 412
  • It looks like Rails is probably doing the right thing, but gmail seems to only allow the 'from' address to be that of the account holder. See this question/answer for details: http://stackoverflow.com/questions/1332510/how-to-change-from-address-when-using-gmail-smtp-server – neuronaut Oct 02 '15 at 23:02
  • Kind of "yeah"; when I check the logs, I see that the email was sent out from the proper email address (`default@email.com`), but in Gmail I see the personal one. – user984621 Oct 02 '15 at 23:07
  • I have a similar but different problem. 'to' address is filled with 'from' address when I call `deliver_now`, but when I check mailer object itself, like `mailer.to`, it shows correct 'to' address. What could be the culprit? – elquimista Nov 21 '19 at 00:19
  • Okay I figured out. There was a mail interceptor that modifies `to` address when running in development environment. – elquimista Nov 21 '19 at 07:15

0 Answers0