【问题标题】:Action mailer doesn't send emailsAction mailer 不发送电子邮件
【发布时间】:2014-06-01 11:42:38
【问题描述】:

有了这个通知器

class Notifier < ActionMailer::Base
default_url_options[:host] = "url"  

def deliver_password_reset_instructions(user)  
  @user = user
  @subject = 'Password reset instructions.'
  @sent_on = Time.now
  #default host is defined in development.rb configuration file
  @edit_password_reset_url = url_for :controller => 'password_reset', :action => 'edit'
  @edit_password_reset_url += "?id=#{user.perishable_token}"
  mail to: user.email
end  
end

并在 config/environments/development.rb 上使用此配置

config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = {
:host => 'localhost',
:port => '3000'
}
# Options: :smtp, :test
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtp.gmail.com',
:port => 587,
:domain => 'gmail.com',
:user_name => 'mymail',
:password => 'mypassword',
:authentication => :plain,
:enable_starttls_auto => true }

什么都不发送,怎么回事?

【问题讨论】:

    标签: ruby-on-rails actionmailer


    【解决方案1】:

    按照本文Actionmailer not working when I change gmail password 设置动作邮件程序

    编辑通知器为:-

    class Notifier < ActionMailer::Base
     default from: "test@example.com"
    
     def deliver_password_reset_instructions(user)  
      @user = user
      @sent_on = Time.now
      #default host is defined in development.rb configuration file
      @edit_password_reset_url = url_for :controller => 'password_reset', :action => 'edit'
      @edit_password_reset_url += "?id=#{user.perishable_token}"
      mail to: user.email, :subject => "Password reset instructions."
     end  
    end
    

    在密码重置控制器中:--

    def create
     #send email as
     Notifier.deliver_password_reset_instructions(user)
    end
    

    app/views/notifier/中创建一个名为deliver_password_reset_instructions.html.erb的页面,并将发送的内容放入邮件中。

    【讨论】:

    • 我在 setup_mail.rb 中设置了操作邮件程序并编辑了通知程序,但仍然无法正常工作
    • 您是否在日志中检查了邮件已发送或发生任何错误?
    • 能否贴出PasswordResetsController创建方法代码。
    猜你喜欢
    • 2013-05-21
    • 2015-08-23
    • 1970-01-01
    • 2015-09-08
    • 2011-05-15
    • 1970-01-01
    • 2011-07-14
    • 1970-01-01
    • 2012-07-25
    相关资源
    最近更新 更多