所以我使用
制作了邮件rails g mailer UserMailer
我的app / mailers / user_mailer.rb:
class UserMailer < ApplicationMailer
default from: 'appointments@gmail.com'
def accepted_appointment(customer)
@customer = customer
@user = User.find(@customer.user_id)
@appointments = @user.appointments.includes(:employee)
mail(to: @user.email, subject: 'Your appointment has beed accepted')
end
end
我的app / views / accepted_appoitnment.html.erb(我知道它有点空,但我想发送一些东西):
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<h1>Hello <%= @customer.first_name %>!</h1>
<p>
</p>
<p>
Thank you very much for using our services!
</p>
<p>Thanks for joining and have a great day!</p>
</body>
</html>
我的config / environments / development.rb
Rails.application.configure do
config.cache_classes = false
config.eager_load = false
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.active_support.deprecation = :log
config.active_record.migration_error = :page_load
config.assets.debug = true
config.assets.digest = true
config.assets.raise_runtime_errors = true
config.action_mailer.default_url_options = { host:
'localhost', port: 3000 }
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
# SMTP settings for gmail
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:user_name => "Myemail@gmail.com",
:password => "Mypassword",
:authentication => "plain",
:enable_starttls_auto => true
}
end
没有任何反应。我的功能,我打电话给accepted_appointment(客户)只是做她的工作,一切都很好,但邮件没有发送。我做错了什么?
编辑:
UserMailer.accepted_appointment(@customer).deliver_later