我定义了一个自定义传递方法,并将其加载到初始化器中:
ActionMailer::Base.add_delivery_method :custom, CustomDelivery
Run Code Online (Sandbox Code Playgroud)
然后我添加config.action_mailer.delivery_method = :custom了development.rb和production.rb.
但是当我想发送电子邮件时
UserMailer.authorize(user).deliver
Run Code Online (Sandbox Code Playgroud)
它失败有关SMTP(东西ArgumentError: A sender (Return-Path, Sender or From) required to send a message
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 deliver!') -这是我不希望使用.
为什么不采用自定义交付方式?
更新:当我从控制台尝试时,我注意到以下内容:
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}>
Run Code Online (Sandbox Code Playgroud)
(顺便说一句,我在我的项目中搜索了"SMTP",并且有0次出现)
Ben*_*Hao -1
您是否通过配置了 SMTP environment.rb?这是我的样子。
ActionMailer::Base.smtp_settings = {
:domain => 'gmail.com',
:address => 'smtp.gmail.com',
:port => 587,
:tls => true,
:authentication => :plain,
:charset => 'utf-8',
:user_name => ENV['GMAIL_USERNAME'],
:password => ENV['GMAIL_PASSWORD'],
:enable_starttls_auto => true
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1263 次 |
| 最近记录: |