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
不显示错误,但电子邮件未发送:(
答案 0 :(得分:0)
用户deliver_now
代替deliver
。
class UsersnewController < ApplicationController
def sendtest
UserMailer.abc().deliver_now
redirect_to root_path
end
end