ruby-on-rails - 如何使用/解决Gmail的SMTP出站发送限制?

标签 ruby-on-rails email smtp

我正在使用我的Gmail Apps for Domain帐户在Rails应用程序中发送标准自动化电子邮件(用户注册,忘记密码,通知管理员新评论等)中的电子邮件,但我担心每天设置500封电子邮件由Google提供。

Google建议一种克服限制的方法是使用多个用户帐户。

因此,我已经设置了10个其他的gmail用户帐户(noreply1,noreply2,noreply3等)-我想跟踪这些帐户中的任何一个在24小时内何时发送了500封电子邮件,并相应地使用空闲帐户。

如何在:user_name中动态设置ActionMailer::Base.smtp_settings值?

这是我当前的设置-注意:即使我将:user_name和:from显式设置为“noreply2”,每次也都从“noreply1”发送:

--- development.rb --- 
    ActionMailer::Base.delivery_method = :smtp
    ActionMailer::Base.smtp_settings = {
        :address => "smtp.gmail.com",
        :port => "587",
        :domain => "mydomain.com",   
        :authentication => :plain,
            :user_name => "noreply1@mydomain.com",
        :password => "password"
    }

--- account.rb --- (MODEL, called via a callback)
after_create :send_welcome_email
...
def send_welcome_email
  #ActionMailer::Base.smtp_settings[:user_name] = 'noreply2@mydomain.com'
  ActionMailer::Base.smtp_settings.merge!({:user_name => "noreply2@mydomain.com"})  
  SubscriptionNotifier.deliver_welcome(self)   
end

--- subscription_notifier.rb --- (MODEL) 
class SubscriptionNotifier < ActionMailer::Base
  def welcome(account)    
    @sent_on = Time.now
    @subject = "Welcome to the App"
    @recipients = account.email
    @from = "noreply2@mydomain.com" 
    @body = { :account => account }
  end
end

最佳答案

您还可以在服务器上设置MTA并将其用于发送邮件。

那就是我们要做的。

您必须将服务器的IP添加为有效的IP,以便在域的SPF记录中发送电子邮件,以免被标记为垃圾邮件。

这样做的另一个好处是,如果执行此操作,则可以将电子邮件的“发件人:”地址设置为您的用户之一,而GMail则无法执行此操作。

关于ruby-on-rails - 如何使用/解决Gmail的SMTP出站发送限制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/626421/

相关文章:

ruby-on-rails - Ruby:通过点击访问值

ruby-on-rails - 搜索表单未路由到 Rails 5.1 中的正确 Controller

html - 在 Outlook 2013 上防止 "if there are problems with how this message is displayed"

Python - smtp 需要身份验证

powershell - 使用 powershell 发送 gmail

ruby-on-rails - 在 Rails 中进行测试时,我是使用 seeds 还是 factory girl 还是两者都使用?

c - 读出 Thunderbird 未读邮件? (Linux、终端)

java - 使用camel聚合器接收多封电子邮件时遇到问题

email - Send-MailMessage : The SMTP server requires a secure connection. .. 服务器响应为 : 5. 5.1 需要身份验证。

ruby-on-rails - 在 current_password 字段中设计更改验证消息