Everything passes without errors, but not a single letter came to the post office. User logs

environment.rb

# environment.rb # Load the Rails application. require File.expand_path('../application', __FILE__) # Initialize the Rails application. Rails.application.initialize! ActionMailer::Base.smtp_settings = { user_name: 'your_sendgrid_username', password: 'your_sendgrid_password', domain: 'yourdomain.com', address: 'smtp.sendgrid.net', port: 587, authentication: :plain, enable_starttls_auto: true } 

user_mailer.rb

 class UserMailer < ApplicationMailer default from: 'notifications@example.com' def welcome_email(user) @user = user @url = 'http://example.com/login' mail(to: @user.email, subject: 'Welcome to My Awesome Site') end end 

users_contoller.rb

 class UsersController < ApplicationController def index @users = User.all end def new @user = User.new end def create @user = User.new(user_params) if @user.save UserMailer.welcome_email(@user).deliver session[:current_user_id] = @user.token redirect_to root_path else render :new end end private def user_params params.require(:user).permit(:email, :password, :first_name, :last_name, :login) end end 

user_mailer / welcome_email.thml.slim

 doctype html html head meta content='text/html; charset=UTF-8' http-equiv='Content-Type' body Welcome to example.com, = @user.name p You have successfully signed up to example.com, your username is: = @user.login p To login to the site, just follow this link: = @url p Thanks for joining and have a great day! 
  • You should be alerted: Unpermitted parameter: password_confirmation , DEPRECATION WARNING and Sent mail to aaa73731919@gmail.com . The problem, apparently, is only with the last: the letter has gone, but where? .. - D-side

2 answers 2

The problem was that the mailer sent a message from an account that does not exist, created a new account and added an appropriate one to the config, and everything went well.

    If I remember correctly (I remember very vaguely), then during initialization, the application saves its copy of smtp_settings and changing them for ActionMailer::Base becomes just pointless. In the logs, it is clear that an attempt was made to send a letter and the letter fell into the console (default behavior for the development environment) It would be more correct to specify the settings for a specific environment in the files config/environments/*.rb because in a test environment, using a mailer is clearly redundant. However, if, after all, you need to set parameters for all environments, then it is better to do this in config/application.eb :

     class Application < Rails::Application #... config.action_mailer.smtp_settings = { #твои настройки } end 

    By the way, (again, if I remember correctly) config/environments/*.rb priority than what is specified in config/application.eb . So, at least for the test, it is possible to return the default behavior.