0

I'm trying to send emails but the emails will never use my :from => code, instead the email always arrives using the 'from' of my gmail smtp settings. So for example the email arrives and says FROM: [email protected] instead of FROM: [email protected] , and in the logs it shows the email sent using the FROM: [email protected] which is from my devise initializer.

How can I fix this? Its really upsetting at the moment :( Thanks for any help.

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            => "[email protected]",
     :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 => "[email protected]",
          :subject => "recover your password"
          )
   end
end

Log

Started GET "/users/password/new" for 127.0.0.1 at 2011-12-04 12:03:22 -0700
  Processing by Devise::PasswordsController#new as HTML
Rendered devise/shared/_links.erb (1.7ms)
Rendered devise/passwords/new.html.erb within layouts/application (2103.3ms)
Completed 200 OK in 2122ms (Views: 2112.1ms | ActiveRecord: 0.8ms)


Started POST "/users/password" for 127.0.0.1 at 2011-12-04 12:03:27 -0700
  Processing by Devise::PasswordsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"hEYh1/G9P0noE+VobBbgremT+rpt+fJFez7H99dOGNM=", "user"=>{"email"=>"[email protected]"}, "commit"=>"Send me reset password instructions"}
  User Load (1.7ms)  SELECT "users".* FROM "users" WHERE "users"."email" = '[email protected]' LIMIT 1
Rendered devise/mailer/reset_password_instructions.html.erb (1.0ms)

Sent mail to [email protected] (3585ms)
Date: Sun, 04 Dec 2011 12:03:28 -0700
From: [email protected]
Reply-To: [email protected]
To: [email protected]
Message-ID: <[email protected]>
Subject: Reset password instructions
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

<p>Hello [email protected]!</p>

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

<p><a href="http://localhost:3000/users/password/edit?reset_password_token=Gg3Aqe6sFD3rDLUAda47">Change my password</a></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>
Redirected to http://localhost:3000/users/sign_in
Completed 302 Found in 4281ms


Started GET "/users/sign_in" for 127.0.0.1 at 2011-12-04 12:03:32 -0700
  Processing by Devise::SessionsController#new as HTML
Rendered devise/shared/_links.erb (1.7ms)
Rendered devise/sessions/new.html.erb within layouts/application (80.7ms)
Completed 200 OK in 340ms (Views: 90.6ms | ActiveRecord: 2.3ms)

1 Answer 1

1

Gmail is changing your from. Get your own mailserver if you don't want modifications.

There is a guide on how to set a different sender when using the mail interface and/or googles servers.

Note for IMAP/POP users: If you access Gmail through a POP or IMAP email client (e.g. Outlook) and would like to send messages with a custom "from" address, you have two options. We recommend that you configure your email client with two outgoing SMTP servers, one for Gmail and one for your other address. Or, you can use Gmail's outbound servers with a different "from" address. If you've already configured the alternate address, your message will be sent from:[email protected], sender:[email protected], regardless of which custom from configuration you chose.

You have to enable your 3rd party address for gmail first. Check the guide linked above. IIRC gmail will set the different address, however the users will still see that its coming from gmail.

1
  • is it really just gmail? there are tons of tutorials online, including this railscasts, which show configuring using gmail smtp but also using a custom :from => inside the mailer method? Dec 4, 2011 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.