2008-10-28 140 views
2

所以我action_mailer_optional_tls(http://svn.douglasfshearer.com/rails/plugins/action_mailer_optional_tls) ,这在我的enviroment.rb通过Gmail发送电子邮件来自不同帐户

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

但现在什么?如果我想从不同的电子邮件帐户发送电子邮件? 如何随时覆盖user_name和密码字段?

我在寻找的是一个解决方案,允许帐户之间的动态切换。示例以下情形: 10“管理员”可以向我们的客户发送通知。每个人都有自己的Gmail帐户,当他们填写表格时,使用他们的帐户轨道连接并发送邮件。

在此先感谢!

阿里

回答

0

如果你想使用不同的电子邮件地址从目标接收器的答复, 您可以指定回复:[email protected] SMTP协议的,仍然使用现有帐号谷歌smtp服务。

但是,您需要转到Gmail设置才能将[email protected]添加到“将电子邮件发送为”列表中,这还需要您通过发送指向该收件箱的链接来确认[email protected]是否属于您。

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 

注意,存储用户的电子邮件密码以明文形式是非常危险的,我不知道是否有什么办法可以做你想要使用的是什么谷歌帐户的third party authentication计划,但你可能要检查了这一点。

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 => "[email protected]", 
    :password => "xxxxxxx", 
    :tls => :true 
} 
config.action_mailer.perform_deliveries = :true 
config.action_mailer.raise_delivery_errors = :true 
config.action_mailer.default_charset = "utf-8" 
+0

答案是由伊万评论在http://douglasfshearer.com/blog/gmail-smtp-with-ruby-on-rails-and复制-actionmailer – 2009-10-14 07:05:19

相关问题