• 提供 HTML 与纯文本两份视图模版。

  • 在开发环境下应显示发信失败错误。这些错误默认是关闭的。

    1. # config/environments/development.rb
    2. config.action_mailer.smtp_settings = {
    3. address: 'localhost',
    4. port: 1025,
    5. }
  • 为域名设置默认项。

  • 若需要在邮件中添加到网站的超链接,应总是使用 方法,而非
    _path 方法。_url 方法产生的超链接包含域名,而 _path
    方法产生相对链接。

    1. # 差
    2. You can always find more info about this course
    3. <%= link_to 'here', course_path() %>
    4. <%= link_to 'here', course_url(@course) %>
  • 确保测试环境下的 email 发送方法设置为 test

    1. # config/environments/test.rb
    2. config.action_mailer.delivery_method = :test
  • 开发环境和生产环境下的发送方法应设置为 smtp