Ask A Question

Notifications

You’re not receiving notifications from this thread.

Sending emails not working, no errors found in the terminal

Felix Pujols asked in General

I'm new on rails, I would appreciate any help. This is the repository of this project: https://github.com/felixpro/Kadra

when a client signup an email is sent to the mail of the admin to approve that client otherwise the client will never be able to log in

I am having problems sending emails, in development and production environment. I have tried everything, but nothing is working for me.

maillers/user_mailer.rb

class UserMailer < ApplicationMailer
  default from: 'from@example.com'
      layout 'mailer'

      def new_user_waiting_for_approval(user)
        @user = user
        mail(to: 'pujols.fr@gmail.com', subject: 'New User Awaiting Admin Approval')
      end

end

controllers/user_controller.rb

 def create
    @user = User.new(user_params)

    respond_to do |format|
      if @user.save
        UserMailer.new_user_waiting_for_approval(@user).deliver_now
        format.html { redirect_to @user, notice: 'User was successfully created.' }
        format.json { render :show, status: :created, location: @user }
      else
        format.html { render :new }
        format.json { render json: @user.errors, status: :unprocessable_entity }
      end
    end
  end
Reply

Real quick, you have your sendgrid PW in your config/envirnments/production.rb. You really should have that in your encyrpted credentails or a local ENV file otherwise it's going to (not might but going to) get stolen.

As far as the issue you're having, I cloned the repo and tried it out. It seems to work fine, an email is sent when a user registers. I even set up a local mail server to catch the emails being sent and was able to see them coming through.

I'm not sure what might be happening in Prod, I'm not that familiar with Heroku. But seems to work fine in Dev. Are you seeing the mail in your logs?

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,464+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.