I would like to customize the registration completion email for Device, but a 555 5.5.2 Syntax error appears and I cannot send it.

Asked 2 years ago, Updated 2 years ago, 107 views

Try sending a registration completion email automatically using Action Mailer and device

Based on the above article, I would like to customize the registration completion email in my application, but after writing down the address on the new registration screen, the following error was issued. If it works correctly, the screen should transition and register with the email address.

555 5.5.2 Syntax error.xxx-gsmtp

The location of the error is the controller below.p>

app/controllers/users/registrations_controllers.rb

#frozen_string_literal:true

class Users::RegistrationsController <Device::RegistrationsController

 # from here

  # qiita-ActionMailer Reference
  def create
    # Call create action for superclass (devise)
    super
    # Call the send_when_signup method of the WelcomeMailer class and pass the user's email and name received from POST.
    WelcomeMailer.send_when_signup(params[:user][:email], params[:user][:name]).deliver
  end

 # That's it.

  # before_action: configure_sign_up_params, only: [:create]
  # before_action: configure_account_update_params, only: [:update]

  # GET/resource/sign_up
  # def new
  #   super
  # end

  # POST/resource
  # def create
  #   super
  # end

  # GET/resource/edit
  # default
  #   super
  # end

  # PUT/resource
  # default update
  #   super
  # end

  # DELETE/resource
  # def destroy
  #   super
  # end

  # GET/resource/cancel
  # Forces the session data which is userally expired after sign
  # in to be expired now. This is useful if the user wants to
  # cancel oauth signing in/up in the middle of the process,
  # removing all OAuth session data.
  # def cancel
  #   super
  # end

  # protected

  # If you have extra params to permit, append them to the sanitizer.
  # def configure_sign_up_params
  #   device_parameter_sanitizer.permit(:sign_up, keys:[:attribute])
  # end

  # If you have extra params to permit, append them to the sanitizer.
  # def configure_account_update_params
  #   device_parameter_sanitizer.permit(:account_update, keys:[:attribute])
  # end

  # The path used after sign up.
  # after_sign_up_path_for (resource)
  #   super(resource)
  # end

  # The path used after sign up for inactive accounts.
  # after_inactive_sign_up_path_for (resource)
  #   super(resource)
  # end
end

As mentioned in the article, I have already added the name, email column, and I have set up a "free" chapter in the article for serviceability when I post it to github, and I have already checked it on the terminal. Why do I get a syntax error?

For your reference, I will list the file I added based on the article, so I would appreciate your advice.

config/env/development.rb

#Additional or Changed
  config.action_mailer.default_url_options={ host:'localhost', port:3000}
  # qiita-ActionMailer --
  # Don't care if the mailer can't send.
  config.action_mailer.raise_delivery_errors=true
  config.action_mailer.delivery_method=: smtp
  config.action_mailer.smtp_settings={
    port:587,
    address: 'smtp.gmail.com',
    domain: 'smtp.gmail.com',
    user_name : ENV ['WELCOME_MAILER_ADDRESS',
    password:ENV['WELCOME_MAILER_PASSWORD',
    authentication: 'login',
    enable_starttls_auto —true
  }

ruby-on-rails ruby gmail devise

2022-09-30 16:58

2 Answers

As you can see in the error message, this is a message that the gsmtp, or Gmail SMTP server, is generating a syntax error.Learn more: https://support.google.com/a/answer/3726730?hl=ja

Therefore, there is a problem with the body and header of the mail.I don't know the details because it doesn't appear in the questionnaire, but please check the actual email data you are trying to send by checking the view and the generated data.

To see what data is being generated, simply try putting and ActionMailer's Mail Preview feature
You can use https://railsguides.jp/action_mailer_basics.html#%E3%83%A1%E3%83%BC%E3%83%AB%E3%81%AE%E3%83%97%E3%83%AC%E3%83%93%E3%83%A5%E3%83%BC.


2022-09-30 16:58

For example, it appears when the email address of To or From is incorrect.
https://stackoverflow.com/questions/4321346/555-5-5-2-syntax-error-gmails-smtp

If you check the contents of SMTP communication, you will find out the details of the error, but if you set config.action_mailer.logger, you will get something.
https://railsguides.jp/configuring.html#config-action-mailer-logger


2022-09-30 16:58

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.