Sending mail with Rails 3 in development environment

前端 未结 8 1173
执念已碎
执念已碎 2020-12-04 06:29

I\'m sure this has been asked a million times before but I can\'t find anything that works for me so I\'m asking again!

I just need a way of sending emails using Act

相关标签:
8条回答
  • 2020-12-04 07:28

    Try using 'sendmail' instead of 'smtp'.

    ActionMailer::Base.delivery_method = :sendmail
    ActionMailer::Base.sendmail_settings = {
      :address              => "smtp.gmail.com",
      :port                 => "587",
      :domain               => "gmail.com",
      :user_name            => "xxx@gmail.com",
      :password             => "yyy",
      :authentication       => "plain",
      :enable_starttls_auto => true
    }
    
    0 讨论(0)
  • 2020-12-04 07:32

    Well I have resolved the issue, but quite why this works and the other methods did not, I don't know.

    The solution was to create an initialiser in config/initialisers/setup_mail.rb containing the following

    if Rails.env != 'test'
      email_settings = YAML::load(File.open("#{Rails.root.to_s}/config/email.yml"))
      ActionMailer::Base.smtp_settings = email_settings[Rails.env] unless email_settings[Rails.env].nil?
    end
    

    I then added config/email.yml containing the details of the dev and production email accounts

    development:
      :address: smtp.gmail.com
      :port: 587
      :authentication: plain
      :user_name: xxx
      :password: yyy
      :enable_starttls_auto: true
    production:
      :address: smtp.gmail.com
      :port: 587
      :authentication: plain
      :user_name: xxx
      :password: yyy
      :enable_starttls_auto: true
    

    Like I say, no idea why, but this seemed to do the trick. Thanks all for the pointers

    0 讨论(0)
提交回复
热议问题