Rails 3: action mailer not usng the :from => parameters

眉间皱痕 提交于 2019-12-01 09:24:11

问题


Hi guys I'm trying to get emails running for a "Contact" page and the emails are coming through just fine but the problem is that the "from" field won't show my :from => "" that's inside my mailer method. The same thing happens with my recover password function which is below. The email which persists in the 'from' field is "myusername@gmail.com" from the smtp settings. Really appreciate the any help with this!

I'm using Gmail and setup my smtp settings like this:

config/initializers/mailer_setup

ActionMailer::Base.smtp_settings = {
     :address              => "smtp.gmail.com",
     :port                 => 587,
     :domain               => "mydomain.com",
     :user_name            => "myusername@gmail.com",
     :password             => "mypassword",
     :authentication       => "plain",
     :enable_starttls_auto => true
     }

mailer/user_mailer.rb

   def reset_password_instructions(user)
     @user = user
     @url  = "http://localhost:3000"
     mail(:to => user.email,
          :from => "test@mydomain.com",
          :subject => "recover your password"
          )
   end
end

views/mailer/rest_password_instructions.html.erb

<p>Hello <%= @resource.email %>!</p>

<p>Someone has requested a link to change your password, and you can do this through the link below.</p>

<p><%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %></p>

<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>

回答1:


Gmail typically doesn't let you set the from field for sending emails. For this reason, a lot of people switch to other mail services like SendGrid.

If you google "Rails gmail from field" you'll unfortunately see all the other people who have struggled with this in the past.



来源:https://stackoverflow.com/questions/8371596/rails-3-action-mailer-not-usng-the-from-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!