我想通过 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 => "[email protected] /cdn-cgi/l/email-protection",
:password => "password"
}
recipients user.email
subject "Test test"
body "Test"
end
end
我想在这里设置用户名和密码。
(铁轨3)
因为我这样称呼邮件程序:
CustomerMailer.customer_auto_inform(@form).deliver
在 CustomerMailer 类中我有私有方法:
def init_email_account(shop_mail)
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.smtp_settings = {
:address => shop_mail.address,
:port => shop_mail.port,
:domain => shop_mail.domain,
:user_name => shop_mail.user_name,
:password => shop_mail.password,
:authentication => shop_mail.authentication.name,
:enable_starttls_auto => shop_mail.enable_starttls_auto
}
end
致电之前mail()它发送电子邮件,您需要调用私有方法初始化电子邮件帐户从数据库填充 smtp_settings。商店邮箱是存储有关邮件帐户设置的数据的模型。
HTH
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)