【问题标题】:How do I set retriever_method not in defaults?如何将retriever_method 设置为不在默认值中?
【发布时间】:2019-12-19 05:37:17
【问题描述】:

delivery 块内立即设置delivery_method 而不是设置defaults 发送 似乎适用于以下代码:

    Mail.deliver do
      delivery_method :smtp,
        address: "smtp.gmail.com",
        domain: "#####",
        port: 587,
        user_name: from,
        password: "#####",
        enable_starttls_auto: true
      from     from
      to       to
      subject  subject
      body     "default body"
    end

但是我该如何阅读呢?

Mail.last do
  retriever_method :imap,
    user_name: to,
    password: password,
    address: server,
    port: port,
    enable_ssl: true
end

原因

*** NoMethodError Exception: undefined method `retriever_method' for #<RSpec::ExampleGroups::Nested::Nested_2::Nested::Email_2:0x00007fa246110478>

【问题讨论】:

    标签: ruby dsl mail-gem


    【解决方案1】:

    仅供参考:这个宝石是 OSS。

    Mail#delivery_method 在技术上是Configuration.instance.delivery_method 的别名。

    Mail#retriever_method 又重定向到Configuration.instance.retriever_method

    不同于Mail::deliver,即creates a new instanceMail::lastexplicitly calls retriever_method.last(*args, &amp;block)

    正如人们所见,instance 允许覆盖 delivery_method,但不允许覆盖 retriever_method

    所以你应该将Configuration.instance.retriever_method 存储到中间变量中,更新它,调用Mail::last 并恢复它。大致上是这样的:

    Configuration.instance.instance_eval do
      generic_retriever_method = retriever_method
      retriever_method :imap,
        user_name: to,
        password: password,
        address: server,
        port: port,
        enable_ssl: true
      Mail.last
      retriever_method = generic_retriever_method
    end
    

    【讨论】:

    • 哦,这就是我害怕的)谢谢你的调查!你推荐其他图书馆吗?
    • 我不知道。我不是使用 3rd 方下摆的忠实粉丝,它们总是有故障。顺便说一句,我提出的解决方法有什么问题?您可能会深入挖掘,甚至分叉和修改它以支持多个检索器;它不应该是复杂或耗时的。只需复制它具有的交付功能 - 瞧。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-04
    相关资源
    最近更新 更多