如何使用/围绕Gmail的SMTP出站发送限制?

Jim*_*nes 6 email smtp ruby-on-rails

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

谷歌建议克服限制的一种方法是使用多个用户帐户.

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

如何动态设置:user_nameActionMailer::Base.smtp_settings

这是我当前的设置 - 注意:每次都从"noreply1"发送,即使我明确设置:user_name和:from from"noreply2":

--- 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
Run Code Online (Sandbox Code Playgroud)

Luk*_*ncl 9

您还可以在服务器上设置MTA并使用它来发送邮件.

这就是我们的工作.

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

这样做的另一个好处是,如果您这样做,您可以将电子邮件的发件人:地址设置为您的用户之一,而GMail则无法做到这一点.