Sending mail with Rails 3 in development environment

前端 未结 8 1172
执念已碎
执念已碎 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:11

    Just put all config to: config/environments/development.rb

    I mean

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

    and

    config.action_mailer.raise_delivery_errors = true
    config.action_mailer.perform_deliveries = true
    

    It worked for me.

    0 讨论(0)
  • 2020-12-04 07:12

    My two pennies worth:

    I had those exact same symptoms with Rails 5.1: Nothing happened, the settings in my development.rb file were utterly ignored...

    Then I remembered to restart the machine! (which solved magically the issue)

    This had been pointed out by a couple of previous comments.

    The issue is tricky however because you do not expect this behavior. In my view, the default comments in development.rb are, in this respect, misleading:

    # In the development environment your application's code is reloaded on
    # every request. This slows down response time but is perfect for development
    # since *you don't have to restart the web server when you make code changes*.
    
    0 讨论(0)
  • 2020-12-04 07:14

    ActionMailer::Base.delivery_method = :sendmail
    and
    config.action_mailer.perform_deliveries = true

    were the two necessary steps that got me over this issue

    0 讨论(0)
  • 2020-12-04 07:15

    I have the following in config/environments/development.rb

    config.action_mailer.raise_delivery_errors = true
    config.action_mailer.perform_deliveries = true
    

    The actual mail-configuration, config.actionmailer.* i have placed in config\application.rb.

    Hope this helps :)

    0 讨论(0)
  • 2020-12-04 07:18

    In addition to, your gmail username does not alias.

    Ref: https://support.google.com/mail/answer/12096?hl=en

    0 讨论(0)
  • 2020-12-04 07:22

    Three things.

    First, the port is an integer and does not need quotes, as in your first example. (But I think a string should still work.)

    Second, don't forget to restart your server each time you modify this (or any) initializer file. This could explain why you didn't see an error after adding:

    config.action_mailer.raise_delivery_errors = true

    Without having that error message, it's hard to determine why the mail wasn't going but now is. One possiblity is your use of double quotes around the password. If you were using a strong password and had a token in your password that wasn't escaped it could have been reinterpreted. (i.e. "P@ssw\0rd" would become P@ssrd). For just this reason, I always use single quotes in my code unless I specifically need the syntactic sugar.

    Lastly, enable_starttls_auto: true is the default and unnecessary.

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