我正在使用我的 Gmail Apps for Domain 帐户在 Rails 应用程序中发送电子邮件以获取标准自动电子邮件(用户注册、忘记密码、通知管理员新评论等),但我担心每天设置的 500 封电子邮件限制由谷歌。
谷歌建议克服该限制的一种方法是使用多个用户帐户。
因此,我设置了 10 个额外的 gmail 用户帐户(noreply1、noreply2、noreply3 等) - 我想跟踪这些帐户中的任何一个在 24 小时内发送了 500 封电子邮件,并相应地使用空闲帐户。
如何动态设置:user_name
值在ActionMailer::Base.smtp_settings
?
这是我当前的设置 - 注意:每次都会从“noreply1”发送,即使我明确设置 :user_name 和 :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 => "[email protected] /cdn-cgi/l/email-protection",
:password => "password"
}
--- account.rb --- (MODEL, called via a callback)
after_create :send_welcome_email
...
def send_welcome_email
#ActionMailer::Base.smtp_settings[:user_name] = '[email protected] /cdn-cgi/l/email-protection'
ActionMailer::Base.smtp_settings.merge!({:user_name => "[email protected] /cdn-cgi/l/email-protection"})
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 = "[email protected] /cdn-cgi/l/email-protection"
@body = { :account => account }
end
end
您还可以在服务器上设置 MTA 并使用它来发送邮件。
这就是我们所做的。
您必须将服务器的 IP 添加为域的 SPF 记录中用于发送电子邮件的有效 IP,以避免被标记为垃圾邮件。
这样做的另一个好处是,如果您这样做,您可以将电子邮件的发件人地址设置为您的用户之一,而使用 GMail 则无法做到这一点。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)