如何使用/绕过 Gmail 的 SMTP 出站发送限制? [英] How can I work with/around Gmail's SMTP outbound sending limits?

查看:32
本文介绍了如何使用/绕过 Gmail 的 SMTP 出站发送限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using my Gmail Apps for Domain account to send email within my rails application for standard automated emails (user signup, forgot password, notify admin of new comment, etc), but I'm worried about the 500 emails per day limit set by Google.

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

Google suggests one way to overcome the limit is to use multiple user accounts.

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

So, I've setup 10 additional gmail user accounts (noreply1, noreply2, noreply3, etc) - I'd like to track when any of these accounts has sent 500 emails in a 24 hour period and use the idle account accordingly.

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

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

Here's my current setup - NOTE: this sends from "noreply1" every time, even though i'm explicitly setting :user_name and :from to "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

推荐答案

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

You could also set up an MTA on your server and use that for sending the mail.

这就是我们所做的.

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

You have to add your server's IP as a valid one for sending email in your domain's SPF record to avoid getting marked as spam.

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

Another benefit of this is that if you do this, you can set the From: address of the email to be one of your users, which you cannot do with GMail.

这篇关于如何使用/绕过 Gmail 的 SMTP 出站发送限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆