【发布时间】:2014-04-23 05:40:07
【问题描述】:
我想通过 Gmail 从我的应用程序发送少量电子邮件。现在,SMTP 设置将在运行时确定(即:从数据库),可以这样做吗?
--- 编辑---
我可以在类的方法之一中设置 ActionMailer 子类(名为 Notifier)的 smtp 设置。这样我可以设置动态发送电子邮件的用户名和密码。唯一的事情是你必须设置所有的 smtp_settings。是否可以在类方法中只设置用户名和密码设置?
这是我现在正在使用的代码,它正在发送:
class Notifier < ActionMailer::Base
def call(user)
Notifier.smtp_settings = {
:enable_starttls_auto => true,
:address => "smtp.gmail.com",
:port => "587",
:domain => "mydomain.com",
:authentication => :plain,
:user_name => "fabian@mydomain.com",
:password => "password"
}
recipients user.email
subject "Test test"
body "Test"
end
end
我想在这里设置用户名和密码。
【问题讨论】:
标签: ruby-on-rails