2010-11-23 57 views
2

我从头开始一个新的Rails 3应用程序。什么是在Rails中设置自定义全局电子邮件默认值的“最佳实践”方法?

而当我正在经历基本设置(配置宝石,会话等)时,我遇到了一些让我唠叨了一阵子的东西。

我们目前的系统(混合使用Ruby脚本& Rails 2应用程序)向客户端发送各种电子邮件/传真通知。在80%的案例中有一些常见的情况 - cc - 我们终端的某些电子邮件帐户和电子邮件签名。

在environment.rb中以前我刚刚定义GLOBALS如

SYSTEM_EMAIL_SIGNATURE 

SYSTEM_EMAIL_NOTIFY 

,并用它们后来在邮寄或者如果它是一个独立的脚本我有一个设置.rb文件 - 有很多常见的设置 - 包括一个像这样的自定义电子邮件设置。

因为我从头开始重建这个应用程序,并将所有脚本整合到一个ruby应用程序中 - 我试图想到一个更好的方法来做到这一点。

现在我设置了有action_mailer设置的email.rb初始化程序,我伸出通过增加数个项目:

 ########## Setup Global Email Defaults ############## 
Site::Application.configure do 
    config.action_mailer.raise_delivery_errors = true 
    config.action_mailer.delivery_method = :smtp 
    config.action_mailer.smtp_settings = { 
    :address => 'mail.example.com', 
    :port => 25, 
    :domain => 'example.com', 
    # These are custom to OUR setup - used later in the code 
    :default_from => 'it.s[email protected]', 
    :default_notify => ["[email protected]"], 
    :default_signature => " 
--------------------------- 
This is an automatic email. 
If you have any questions please contact customer service 
at 1 (800) 888-0000 or go to http://www.example.com. 
Thank you for your business!" 

    } 



end 

所以这是一个好办法?或者这两种方法有更好的方法吗?

回答

2

我认为你在default_from和default_notify的正确轨道上。 我不会使用SMTP设置;这些不是SMTP设置,它们只是一般的邮件设置。

我会像这样的东西进去的初始化:

MAILER_SETTINGS = YAML::load(open(File.join(Rails.root, "config", "mailer.yml")).read)[Rails.env] 

随着YAML文件看起来像这样:

development: &development 
    default_from: [email protected] 
    default_notify: ["[email protected]"] 

production: 
    <<: *development 
    default_from: [email protected] 

这可以让你设置的默认值,然后将它们串联起来下来,根据需要覆盖每个环境。

但是,对于签名,我只是将其移入部分,然后将其包含在邮件模板中。他们像任何其他的意见,可以有布局,部分,所有这一切。

+0

感谢您的指针! – konung 2010-11-24 15:49:56

相关问题