电子邮件未发送且没有错误导轨

时间:2016-04-20 09:56:22

标签: ruby-on-rails smtp

 config.action_mailer.default_url_options = { host: 'http://localhost:3000/', port: 3000 }

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.perform_deliveries = true
  config.action_mailer.smtp_settings = {
    :address              => "smtp.gmail.com",
    :port                 => 587,
    :domain               => 'mail.google.com',
    :user_name            => 'xxxx@gmail.com',
    :password             => 'xxx@44',
    :authentication       => 'plain',
    :enable_starttls_auto => true
  }

邮件程序代码

class UserMailer < ActionMailer::Base

  def abc
    mail(to: 'testdigi02@gmail.com', subject: 'here',from: 'jaskaransingh@gmail.com')
        mail to: 'testdigi02@gmail.com', from: 'jaskaransingh@gmail.com', subject: 'test email'

  end
end


class UsersnewController < ApplicationController
    def sendtest 
        UserMailer.abc().deliver 
        redirect_to root_path
    end
 end

不显示错误,但电子邮件未发送:(

1 个答案:

答案 0 :(得分:0)

用户deliver_now代替deliver

class UsersnewController < ApplicationController
    def sendtest 
        UserMailer.abc().deliver_now
        redirect_to root_path
    end
 end