ruby-on-rails - Rails 邮件程序不发送电子邮件
问题描述
当我尝试使用 rails (5.1.4) 邮件程序时,我没有收到任何我应该做的电子邮件。我按照官方的 Rails 指南来制作它。我的 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
}
有了这个配置,我在 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
此邮件由控制器控制的表单触发,它位于 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
表单正确显示闪存“一些消息”,并且控制台中没有写入错误。
解决方案
您需要deliver_now
打电话给邮寄者。
AppointementMailer.appointement_information(@appointement['email'], @appointement['body']).deliver_now
推荐阅读
- git - 从终端创建项目时 Gitlab 默认项目可见性
- python - 如何在 Django 视图中使用 for 循环返回每次迭代
- javascript - 邮件脚本返回带有登录页面的电子表格,而不是电子表格数据
- sql - 使用 sql 在列级别获取最近 2 个月的员工人数?
- r - 如何为 plotly sunburst 图格式化数据
- excel - 当我在列表视图中过滤并选择过滤器行并输入一些值时,在列表视图中是正确的,但在 excel 中出现在第一行
- django - 如何在 ModelSerializer 上获取自定义字段
- android - Kotlin 注释 @Parcelize 可靠性
- excel - 将范围复制到目的地并返回目的地范围
- python - 使用 python 下载 jpg 时出错导致:[SSL: CERTIFICATE_VERIFY_FAILED]