Skip to main content

Sending emails not working, no errors found in the terminal

General • Asked by Felix Pujols

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: '[email protected]'
      layout 'mailer'

      def new_user_waiting_for_approval(user)
        @user = user
        mail(to: '[email protected]', 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

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?


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 22,346+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.