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

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

问题描述

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

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等) - 我想跟踪这些帐户中有哪些帐户发送了500在24小时内发送电子邮件,并相应地使用空闲帐户。

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

How do I dynamically set the :user_name value in ActionMailer::Base.smtp_settings?

这是我当前的设置 - 注意:每次都会发送noreply1,即使我明确设置:user_name和:从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.

另一个好处是,如果您这样做,您可以将电子邮件的发件人地址设置为您的用户之一,您不能使用此功能。

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天全站免登陆