When I try to use rails (5.1.4) mailer, I don't receive any email like I should do. I followed the official rails guide to make it. My config/environment/development.rb :
当我尝试使用rails(5.1.4)邮件程序时,我没有收到任何像我应该做的邮件。我按照官方的导轨指南来制作它。我的config / environment / development.rb:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'gmail.com',
user_name: 'username@gmail.com',
password: 'app-password-from-google',
authentication: 'plain',
enable_starttls_auto: true
}
With this config I made a new mailer in mailers/appointement_mailer.rb :
使用此配置,我在mailers / appointement_mailer.rb中创建了一个新的邮件程序:
class AppointementMailer < ApplicationMailer
default :from => "username@gmail.com"
def appointement_information(user_email, data)
@email = user_email
@body = data
mail(:to => "username@gmail.com", :subject => "xxx")
end
end
This mailer is triggered by a form controlled by a controller, it is located under controllers/contacts_controller.rb :
此邮件程序由控制器控制的表单触发,它位于controllers / contacts_controller.rb下:
def new
end
def create
@appointement = appointement_params
AppointementMailer.appointement_information(@appointement['email'], @appointement['body'])
flash[:notice] = "Some message"
redirect_to articles_path
end
private
def appointement_params
params.require('appointement').permit(:email, :body)
end
The form correctly display the flash "Some Message" and no error is written in the console.
表单正确显示闪存“Some Message”,并且控制台中没有写入错误。
1 个解决方案
#1
1
You need to call deliver_now
on your call to the mailer.
您需要在致电邮件时致电deliver_now。
AppointementMailer.appointement_information(@appointement['email'], @appointement['body']).deliver_now
#1
1
You need to call deliver_now
on your call to the mailer.
您需要在致电邮件时致电deliver_now。
AppointementMailer.appointement_information(@appointement['email'], @appointement['body']).deliver_now