【问题标题】:SendGrid or Devise Conflict with Mail GemSendGrid 或与 Mail Gem 设计冲突
【发布时间】:2018-02-01 01:47:10
【问题描述】:

我刚刚将 ActionMailer 配置为使用 SendGrid,以便我可以将它与设计电子邮件一起使用。电子邮件部分运行良好,但现在我无法完成迁移。我得到的错误是“TypeError: Mail is not a module”,并显示在下面的代码块中。

$ rake db:migrate
rake aborted!
TypeError: Mail is not a module
.../ruby-2.3.4/gems/mail-2.7.0/lib/mail.rb:3:in `<top (required)>'
.../ruby-2.3.4/gems/activesupport-5.0.6/lib/active_support/dependencies.rb:293:in `require'
.../ruby-2.3.4/gems/activesupport-5.0.6/lib/active_support/dependencies.rb:293:in `block in require'
.../ruby-2.3.4/gems/activesupport-5.0.6/lib/active_support/dependencies.rb:259:in `load_dependency'
.../ruby-2.3.4/gems/activesupport-5.0.6/lib/active_support/dependencies.rb:293:in `require'

认为这个问题与 ActionMailer gem 依赖于 Mail gem(其中包括一个名为 mail.rb:3 的“邮件”模块)的事实有关,并且有一些类在 'devise/test/mailers/email_changed_test.rb' 和 'devise/test/mailers/confirmation_instructions_test.rb' 中也称为 'mail'。

也许这个冲突是由 rails/gem 版本不兼容引起的? (我使用的是 rails 5.0.4、mail 2.7.0、devise 4.3.0。)或者我完全没有抓住重点?

【问题讨论】:

  • 好的,看起来如果我从 rake 任务中删除 'include SendGrid',我可以成功运行 rake。但是,我无法成功运行包括通过 SendGrid 发送电子邮件的 rake 任务。有趣的是,在 ApplicationController 中保留“include SendGrid”并不会产生与我之前收到的相同的错误(或尚未产生错误)。
  • 我有同样的问题,当我删除 include SendGrid 时它会工作......你找到解决方案了吗?
  • @MahmoudM.Abdel-Fattah 好吧,我不记得我在 2 月份是如何解决这个确切问题的,但我最近确实遇到了类似的问题,这就是我解决它的方法(或绕过它)...我没有将 SendGrid 包含在 rake 任务中,而是将其放在邮件文件中(例如,class DeviseMailer &lt; ApplicationMailer),并在该邮件程序中创建了一个方法,该方法实际上执行 SendGrid 功能来发送电子邮件。然后我从 rake 任务中调用了该方法。希望有帮助!

标签: ruby-on-rails ruby devise actionmailer sendgrid


【解决方案1】:

我在这里找到了答案: https://github.com/sendgrid/sendgrid-ruby/blob/master/TROUBLESHOOTING.md#rails-specifics

Rails 自己的 Mail 类和 sendgrid 类 Mail 之间的命名空间冲突。为避免该问题,请改用SendGrid::Mail

sendgrid 类 Email 和您自己定义的 Email 类之间可能会发生命名空间冲突。为避免这些问题,您可以跳过include SendGrid 行并使用SendGrid:: 前缀作为电子邮件。请参阅此 SO 答案了解详情。

【讨论】:

    猜你喜欢
    • 2013-07-19
    • 1970-01-01
    • 2015-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-23
    相关资源
    最近更新 更多