ruby-on-rails - Ruby on Rails - 在生产中未收到“欢迎电子邮件”
问题描述
当通过 Action Mailer 创建新用户时,我正在尝试发送欢迎电子邮件。我在这里遵循了指南:https ://guides.rubyonrails.org/action_mailer_basics.html
在 localhost:3000 上创建用户时电子邮件成功,但是当我在生产环境(Heroku)中部署和测试时,没有成功。
更糟糕的是,我没有在 Heroku 日志中看到错误。
我现在不确定要检查什么。由于配置相同,我已尝试将所有内容移至我的 application.rb 文件(请参阅:ActionMailer doesn't work in production)
我认为它可能会发送延迟消息,但我已经尝试过
UserMailer.with(user: @user).welcome_email.deliver_later
了deliver_now
配置/应用程序.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'gmail.com',
user_name: ENV["GMAIL_USERNAME"],
password: ENV["GMAIL_PASSWORD"],
authentication: 'plain',
enable_starttls_auto: true }
配置/环境/production.rb
config.action_mailer.raise_delivery_errors = false
config.action_mailer.perform_caching = false
邮件程序/user_mailer
class UserMailer < ApplicationMailer
default from: 'pickleballsocial@gmail.com'
def welcome_email
@user = params[:user]
@url = 'https://pickleballsocial.herokuapp.com'
mail(to: @user.email, subject: 'Welcome Pickleball Social')
end
end
users_controller
def create
@user = User.new(user_params)
respond_to do |format|
if @user.save
session[:user_id] = @user.id
# Tell the UserMailer to send a welcome email after save
UserMailer.with(user: @user).welcome_email.deliver_later
format.html { redirect_to(@user, notice: 'User was successfully created.') }
format.json { render json: @user, status: :created, location: @user }
#redirect_to user_path(@user)
else
format.html { render action: 'new' }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
解决方案
我没有看到您的代码有任何重大问题。我要检查的第一件事是确保凭据正确。如果这不是问题,没有日志信息,我不确定问题所在。
推荐阅读
- linux - 在 Ubuntu-18.04 上编译 LibreOffice-6.0.7 时出错
- html - Ionic Angular ion-img 和后备图像问题
- python - ModelForm 中外键的表单字段,ModelChoiceField 的选择太多?
- pymongo - "_id" 字段设置为 int,但是对于带有 "." 的无效文档键会引发 bson 错误。
- winapi - 如何在 Windows 中缩放/缩放窗口?
- firebase - Flutter Child State 未根据更改的父状态更新:FlutterFirestore Stream
- c# - azure 函数的 API 速率限制
- python-xarray - 如何使用 cfgrib 从 HRR 中提取剪切变量?
- java - swagger 将表中的属性显示为重复
- python - 根据常见日期过滤多个数据框