加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails-3 – 为什么Rails没有选择我的自定义邮件传递方法

发布时间:2020-12-17 01:19:51 所属栏目:百科 来源:网络整理
导读:我定义了一个自定义传递方法,并将其加载到初始化器中: ActionMailer::Base.add_delivery_method :custom,CustomDelivery 然后我将config.action_mailer.delivery_method =:custom添加到development.rb和production.rb. 但是当我想发送电子邮件时 UserMaile
我定义了一个自定义传递方法,并将其加载到初始化器中:
ActionMailer::Base.add_delivery_method :custom,CustomDelivery

然后我将config.action_mailer.delivery_method =:custom添加到development.rb和production.rb.

但是当我想发送电子邮件时

UserMailer.authorize(user).deliver

它失败了与SMTP相关的东西(ArgumentError:发送邮件所需的发件人(Return-Path,Sender或From))
来自/Users/me/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/mail-2.4.4/lib/mail/network/delivery_methods/smtp.rb:99:in交付!’) – 我不想用.

为什么不采用自定义交付方式?

更新:
当我从控制台尝试时,我注意到以下内容:

irb(main):019:0> UserMailer.delivery_method
=> :custom

irb(main):020:0> UserMailer.authorize(user).delivery_method 
=> #<Mail::SMTP:0x00000100bdc738 @settings={:address=>"localhost",:port=>25,:domain=>"localhost.localdomain",:user_name=>nil,:password=>nil,:authentication=>nil,:enable_starttls_auto=>true,:openssl_verify_mode=>nil,:ssl=>nil,:tls=>nil}>

(顺便说一句,我在我的项目中搜索了“SMTP”,并且有0次出现)

解决方法

使用自定义交付类配置action_mailer delivery_method:
config.action_mailer.delivery_method = MyCustomDelivery

该课程应该实现交付!获取Mail gem实例的instance方法.像这样的东西:

class MyCustomDelivery
  def deliver!(mail)
    puts "MAIL FROM: #{mail.from}"
    puts "RCPT TO: #{mail.to}"
    puts "DATA: #{mail.to_s}"
  end
end

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读