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)) 为什么不采用自定义交付方式? 更新: 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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |