I have a Rails 7 app using Ruby 3.2.2 up on Heroku. It uses SendGrid to send thank you emails when someone signs up for the newsletter of fills out the contact form. I have the SendGrid account validated both single email address and the domain. Of course I have the api key for the password. By default they use the string "apikey" for the username. I have the mailers set up and configured. I have the SendGrid info configured in the production.rb. The main page is the landing page and has the landing controller. When the form is submitted, the landing controller has the create action. If certain checks are met, and if model.save to the database, then the email is sent, passing certain information to the mailer. I development this works wonderfully and emails are being relayed through SendGrid to the appropriate addresses. For the newsletter it is just a thank you to the email provided. For the contact form, one goes to the admin which is plucked from the users with the role, and the thank you to the recipient.
I can see the environment variables in the Heroku environment, both from the dashboard and have verified them in runtime. I keep getting this error in the production console log though, and a fetch error from turbo in the browser.
ArgumentError (SMTP-AUTH requested but missing secret phrase):
It seems that the auth sent in the request is missing. This feels like the password is not there. I do not understand the disconnect of this working in development but not production. It may be a aysnc problem? However I am not getting the error I would expect. I invite anyone to assist me in this troubleshooting as I am running in circles. To note, I have not added the SendGrid gem. I am getting the information saved to the database. Again, this works in dev, error in prod, which has me thinking a config issue, just don't see it. Here is some relevant code:
production.rb config
/# config action mailer per devise
config.action_mailer.default_url_options = { host: 'https://xxx.herokuapp.com/', port: 3000 }
/# Setting Action Mailer for smtp through sendgrid.net
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.sendgrid.net',
port: 587,
user_name: 'apikey',
password: Rails.application.credentials.dig(:sendgrid_password),
authentication: 'plain',
enable_starttls: true
}
create action
checks for privacy policy before continuing.
/# POST /landing/newsletter
/# Create a newsletter from the landing page
def create_newsletter
@newsletter = Newsletter.new(newsletter_params)
if newsletter_params[:pp_check] == "0" || newsletter_params[:pp_check] == false
redirect_to root_path, alert: "Please check the privacy policy"
else
respond_to do |format|
if @newsletter.save
/# Send email to driver
NewsletterMailer.new_newsletter_email(@newsletter).del
iver_now
format.html { redirect_to root_path, notice: "Thank you for signing up!" }
else
format.html { redirect_to root_path, alert: "Failed to sign up" }
end
end
end
end
ApplicationMailer.rb
default from email is verified single in sendgrid.
class ApplicationMailer < ActionMailer::Base
default from: "[email protected]"
layout "mailer"
end
I have reviewed docs for both SendGrid and Heroku. Have changed prod.rb config for smtp. Have tried several new api keys. Have had a conversation with Codium regarding different things to try which focused on the env variables. Have ensured the email and domain are verified in SendGrid. Have reviewed several video tutorials.
I would love to be steered in the right direction. This feels like a simple solution that I am missing because I have stared at it to long.