I'm attempting to send a welcome email when a new user is created via Action Mailer. I've followed the guide here: https://guides.rubyonrails.org/action_mailer_basics.html
The email is successful when creating a user on localhost:3000, but when I deploy and test in production environment (Heroku), no success.
Even worse, I'm not seeing errors in the Heroku logs.
I'm not really sure what to check at this point. I've tried moving everything to my application.rb file since the configuration is the same (see: ActionMailer doesn't work in production)
I thought that it may be sending a delayed message, but I've already tried
UserMailer.with(user: @user).welcome_email.deliver_later as well as deliver_now
config/application.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 }
config/environments/production.rb
config.action_mailer.raise_delivery_errors = false
config.action_mailer.perform_caching = false
mailers/user_mailer
class UserMailer < ApplicationMailer
default from: '[email protected]'
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
ENVis the same as what you tested onlocalhost? - lurker