I have generated a project with Ruby on Rails 6 API and I have configured an email account and generated a mailer but I cannot get it to be sent in mail, it should be noted that in the console it appears as sent
This is the controller that sends the mailer to the indicated user's email
class PasswordResetsController < ApplicationController
before_action :set_user, only: [:edit, :update]
KEYS = [:password, :password_confirmation].freeze
def create
user = User.find_by(email: params[:email])
if user
user.generate_password_token!
UserMailer.reset_password(user).deliver_now
end
render json: :ok
end
end
This is the email
class UserMailer < ApplicationMailer
def reset_password(user)
@user = user
mail(to: @user.email, subject: 'Reestablecer contraseña' )
end
end
this is the view
Hi <%= @user.full_name %>,
You have requested to reset your password.
Please follow this link:
<%= "http://localhost:8080/#/password_resets/#{@user.reset_password_token}" %>
Reset password URL is valid within 24 hours.
Have a nice day!
So my config/enviroments/development.rb file in the smtp section
config.action_mailer.perform_caching = false
# Mailer configuration
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.live.com",
:port => 25,
:user_name => "[email protected]", # the email of the account to send emails
:password => "****", # the password of the account to send emails
:authentication => "plain",
:enable_starttls_auto => true
}
and finally my app/mailers/application_mailer.rb
class ApplicationMailer < ActionMailer::Base
default from: '[email protected]
layout 'mailer'
end
This is my console output but the email does not reach the configured account. It should be noted that [email protected] is only for reference and the account that I have configured is a personal account.
> UserMailer#reset_password: processed outbound mail in 5.9ms Delivered
> mail [email protected] (2005.5ms)
> Date: Mon, 01 Jun 2020 23:38:37 -0500 From: [email protected] To:
> [email protected] Message-ID:
> <[email protected]> Subject:
> =?UTF-8?Q?Reestablecer_contrase=C3=B1a?= Mime-Version: 1.0 Content-Type: multipart/alternative;
> boundary="--==_mimepart_5ed5d7cd9bc5e_168444a749c551dc";
> charset=UTF-8 Content-Transfer-Encoding: 7bit
>
>
> ----==_mimepart_5ed5d7cd9bc5e_168444a749c551dc Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit
>
> Hi ,
>
> You have requested to reset your password. Please follow this link:
> http://localhost:8080/#/password_resets/**************** Reset
> password URL is valid within 24 hours.
>
> Have a nice day!
I am trying to set up a personal account. Could you guide me on how to set up the account? Thank you
I don't have account to confirm it, but
port
I think it should be 587 .The other thing is that the
address
apparently has been updated and it may be outlook.office365.com or smtp-mail.outlook.com , I don't know which one it may be, but try both.Finally, try mailcatcher to check locally if it is actually sending the emails.
I have been able to receive the email through mailcatcher, the error was in:
app/mailers/application_mailer.rb
which replaces by