2

所以我有 action_mailer_optional_tls (http://svn.douglasfshearer.com/rails/plugins/action_mailer_optional_tls),这在我的 enviroment.rb

ActionMailer::Base.server_settings = {
  :tls => true,
  :address => "smtp.gmail.com",
  :port => "587",
  :domain => "www.somedomain.com",
  :authentication => :plain,
  :user_name => "someusername",
  :password => "somepassword"
}

但是现在如果我想从不同的电子邮件帐户发送电子邮件怎么办?如何即时覆盖用户名和密码字段?

我正在寻找的是一种允许在帐户之间动态切换的解决方案。例如以下场景:10 个“管理员”可以向我们的客户发送通知。每个人都有自己的 gmail 帐户,当他们在网站上填写表格时,rails 使用他们的帐户连接并发送邮件。

提前致谢!

阿里

4

3 回答 3

1

我现在无法验证这是否有效,但您应该尝试即时修改这些设置。即在发送电子邮件之前从用户帐户中设置用户名/密码。您甚至可以在控制器上设置一个前置过滤器来加载该信息。

before_filter :load_email_settings

def load_email_settings
  ActionMailer::Base.server_settings.merge!(:user_name => current_user.email, :password => current_user.email_password)
end

def current_user
   @current_user ||= User.find(session[:user_id])
end

请注意,将用户电子邮件密码存储为纯文本是非常危险的,我不知道是否有任何方法可以使用 Google 帐户的 第三方身份验证方案来执行您想要的操作,但您可能想检查一下。

于 2008-10-28T18:36:30.507 回答
0

如果您想为目标接收者的回复使用不同的电子邮件地址,您可以为 SMTP 协议指定 Reply-To: otheremail@example.com 并仍然使用 google smtp 服务的现有帐户。

但是,您需要转到 Gmail 设置以将 otheremail@example.com 添加到“发送电子邮件为”列表中,这还需要您通过发送指向该收件箱的链接来确认 otheremail@example.com 是您的。

于 2008-10-28T08:42:58.023 回答
0

从 Rails 2.3 开始,action_mailer_optional_tls插件不是必需的。相反,您应该将以下内容放入您的environment.rb:

config.action_mailer.delivery_method = :smtp 
config.action_mailer.smtp_settings = { 
  :enable_starttls_auto => :true, 
  :address => "smtp.gmail.com", 
  :port => 587, 
  :domain => "mydomain.example.com", 
  :authentication => :plain, 
  :user_name => "myaddress@example.com", 
  :password => "xxxxxxx", 
  :tls => :true 
} 
config.action_mailer.perform_deliveries = :true 
config.action_mailer.raise_delivery_errors = :true 
config.action_mailer.default_charset = "utf-8"
于 2009-10-14T07:03:09.657 回答