Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Sending mail via (Gmail smtp), but with different "from:" address


  • Please log in to reply
6 replies to this topic

#1 Rowel

Rowel

    Controller

  • Members
  • 109 posts

Posted 13 October 2013 - 07:31 PM

I have my send mail working, using gmail as my smtp. 

 

 

Here's my development.rb environment. 

  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    address:              'smtp.gmail.com',
    port:                  587,
    domain:               'mydomain.com',
    user_name:            'myname@gmail.com',
    password:             'mypassword1234',
    authentication:       'plain',
    enable_starttls_auto: true  }

On my UserMailer, I have

class UserMailer < ActionMailer::Base
    default from: 'do-not-reply@mydomain.com'
...
...
...

But the FROM address isn't being changed to "do-not-reply@mydomain.com".... Instead the user receives the transactional emails as coming from "myname@gmail.com" 

 

I think this is a Gmail security feature (can't override the FROM), but I want to really change the FROM name. 

 

What do you guys do in a situation like this? What mail server do you use?  



#2 Bharat Soni

Bharat Soni

    Dispatcher

  • Members
  • 53 posts
  • LocationAhmedabad

Posted 14 October 2013 - 12:29 PM

Hi,

 

I am also got that situation in my past application..............and the solution regarding it the below section my help you, i have already used that in application..

 

in your mailer model use like this

 
mail :to => email_id,
      :from => "do-not-reply@mydomain.com",

      :subject => "Your Subject" 


Fun with Ruby on Rails


#3 Rowel

Rowel

    Controller

  • Members
  • 109 posts

Posted 14 October 2013 - 05:15 PM

in your mailer model use like this

 
mail :to => email_id,
      :from => "do-not-reply@mydomain.com",

      :subject => "Your Subject" 

 

 

 
Nope, I wished that worked.  Tried it, and while the rails console shows it going out as From: do-not-reply@......  ,  when the recipient gets the actual email message, it's still
From: myname@gmail.com  


#4 Bharat Soni

Bharat Soni

    Dispatcher

  • Members
  • 53 posts
  • LocationAhmedabad

Posted 15 October 2013 - 05:47 AM

Try this in config/initilizers/application.rb

config.action_mailer.default_url_options = { :host => "example.com" }

Fun with Ruby on Rails


#5 Rowel

Rowel

    Controller

  • Members
  • 109 posts

Posted 15 October 2013 - 10:15 PM

Sorry, I think it's a Google security override feature.  They change the FROM when you sent mail using their SMTP.

 

What services do people use for their transactional email?  I know Heroku doesn't have it's own smtp, right? 



#6 Ohm

Ohm

    Guard

  • Members
  • 179 posts
  • LocationCopenhagen

Posted 16 October 2013 - 05:17 AM

It's true that Heroku does not have their own SMTP, however, if you can settle with under 6,000 emails per month, SendGrid is still free on Heroku. I use it with the following in the production.rb-file

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
  address:              'smtp.sendgrid.net',
  port:                 '587',
  authentication:       :plain,
  user_name:            ENV['SENDGRID_USERNAME'],
  password:             ENV['SENDGRID_PASSWORD'],
  domain:               'herokuapp.com',
  enable_starttls_auto: true
}

  • Rowel likes this

Blog: http://ohm.sh | Twitter: madsohm


#7 Rowel

Rowel

    Controller

  • Members
  • 109 posts

Posted 16 October 2013 - 06:13 PM

I found this.... you don't even need to host with Heroku.

 

http://mandrill.com/    -- run by the same people running MailChimp

 

12,000 free emails per month... over that, you pay $0.20 / thousand. 

 

Ruby gem here https://github.com/t...ltancy/mandrill

 

Haven't tried it out yet thought. 






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users