500 (Internal Server Error) When I try to send an email in the Rails production environment

Asked 2 years ago, Updated 2 years ago, 130 views

Status

In the inquiry function of the application deployed to AWS (EC2)
If you press the Send button on the confirmation screen,
A heading error occurs.
It works fine in the local environment.
I would like to know how to solve this problem.

The error screen displayed by Chrome shows the following:

Net::OpenTimeout in InquiryController #thanks

Enter a description of the image here

If you press the Send button from the confirmation screen of your inquiry,
The query controller's thanks method is called specification.
Your inquiry will be emailed to your administrator.

Tried

IPv6 was disabled but not resolved.

environment

Ruby 2.6.6
Rails 5.2.4.4
Unicorn 6.0.0
Nginx 1.16.1
MySQL 8.0.23

Related Files

app/controllers/equity_controller.rb

class InquiryController<ApplicationController
  def index
    # Display Input Screen
    @inquiry=Inquiry.new
    render:action=>"index"
  end

  def confirm
    # Checking Input Values
    @quiry=Inquiry.new(quiry_params)
    [email protected] lid?
      # OK. Show confirmation screen
      render:action=>"confirm"
    else
      # NG. Redisplay Input Screen
      render:action=>"index"
    end
  end

  def thanks
    # sending an e-mail
    @quiry=Inquiry.new(quiry_params)
    InquiryMailer.received_email(@quiry).deliver

    # Display the completion screen
    render:action=>"thanks"
  end

  private

  def inquiry_params
    param.require(:quiry).permit(:name,:email,:message)
  end
end
~
~

app/views/quiry/confirm.html.erb

<div class="newWrap">
  <div class="newTitle">
    <h1>Send with the following:Would that be all right?</h1>
  </div>
  <div class="confirm-contents">
    <%=form_for@quiry, :url=>quiry_thanks_path do|f|%>
    <div class="confirm-items">
      <div class="col-sm-4">Name</div>
      <div class="col-sm-8">%=f.hidden_field:name%>%=@i nquiry.name%>>/div>
      <div class="col-sm-4">mail address</div>
      <div class="col-sm-8">%=f.hidden_field:email%>%[email protected]%>/div>;
      <div class="col-sm-4">Contact Us</div>
      <div class="col-sm-8">%=f.hidden_field:message%>%=simple_format(@quiry.message)%>/div>;
    </div>
    <div class="button_wrapper">
      <%=f.submit "Send", class: "btn btn-block btn-success" %>
    </div>
    <%end%>
  </div>
</div>

production.log

< preleukemia > < code > to - to vent our frustration - ~ : Omitted I, [2021-03-25T03:51:10.419286 #3357] INFO -- : [43d3f26b-4a66-4d78-a817-51cd935f0975] Started POST "/inquiry/thanks" for 114.162.4.244 at 2021-03-25 03:51:10 +0000 I, [2021-03-25T03:51:10.419954 #3357] INFO -- : [43d3f26b-4a66-4d78-a817-51cd935f0975] Processing by InquiryController#thanks as HTML I, [2021-03-25T03:51:10.420022 #3357] INFO -- : [43d3f26b-4a66-4d78-a817-51cd935f0975] Parameters: {"utf8"=>"✓", "authenticity_token"=>"jkuENBblLt6WHV22cqg6HxPHJMrkJXSZEc3xDGcNRb7pWcaxLTxAFKdcIfObc6XyWdwebosBlQ36dWeN/YGvcA==", "inquiry"=>{"name"=>"テスト太郎", "email"=>"[email protected]", "message"=>"test"}, "commit"=>"送信する"} I, [2021-03-25T03:51:10.424943 #3357] INFO -- : [43d3f26b-4a66-4d78-a817-51cd935f0975] Rendering inquiry_mailer/received_email.html.erb I, [2021-03-25T03:51:10.425475 #3357] INFO -- : [43d3f26b-4a66-4d78-a817-51cd935f0975] Rendered inquiry_mailer/received_email.html.erb (0.4ms) I, [2021-03-25T03:51:10.426044 #3357] INFO -- : [43d3f26b-4a66-4d78-a817-51cd935f0975] Rendering inquiry_mailer/received_email.text.erb I, [2021-03-25T03:51:10.426457 #3357] INFO -- : [43d3f26b-4a66-4d78-a817-51cd935f0975] Rendered inquiry_mailer/received_email.text.erb (0.3ms) D, [2021-03-25T03:51:10.427877 #3357] DEBUG -- : [43d3f26b-4a66-4d78-a817-51cd935f0975] InquiryMailer#received_email: processed outbound mail in 6.9ms I, [2021-03-25T03:51:40.444459 #3357] INFO -- : [43d3f26b-4a66-4d78-a817-51cd935f0975] Sent mail to [email protected] (30016.3ms) D, [2021-03-25T03:51:40.444553 #3357] DEBUG -- : [43d3f26b-4a66-4d78-a817-51cd935f0975] Date: Thu, 25 Mar 2021 03:51:10 +0000 From: [email protected] To: [email protected] Message-ID: <605c08ae68c71_d1d129b9a855597@ip-10-0-0-81.ap-northeast-1.compute.internal.mail> Subject: =?UTF-8?Q?=E3=82=A4=E3=83=B3=E3=82=B9=E3=82=BF=E6=98=A0=E3=81=88=E3=82=8B=E3=82=93=E5=88=A9=E7=94=A8=E8=80=85=E3=81=8B=E3=82=89=E5=95=8F=E3=81=84=E5=90=88=E3=82=8F=E3=81=9B=E3=81=8C=E3=81=82=E3=82=8A=E3=81=BE=E3=81=97=E3=81=9F?= Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="--==_mimepart_605c08ae683fa_d1d129b9a8554b3"; charset=UTF-8 Content-Transfer-Encoding—7 bits ----==_mimepart_605c08ae683fa_d1d129b9a8554b3 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding:quoted-printable --------------------------<br>=0D Name: =E3=82=A2=E3=82=B5=E3=83=8E=E3=83=A4=E3=82=B9=E3=83=92=E3=83=AD<br>= = 0D Email: [email protected]<br>=0D Message: aa<br>=0D -------------------------= ----==_mimepart_605c08ae683fa_d1d129b9a8554b3 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding—base64 PGgxPuOBiuWVj+OBhOWQiOOCj+OBm+WGheWuuTwvaDE+DQpOYW1lOiDjgqLj grXjg47jg6Tjgrnjg5Ljg608YnI+DQpFbWpbDogbWV6b25nYXdhQGdtYWls LmNvbTxicj4NCk1lc3NhZ2U6IGFhPGJyPg== ----==_mimepart_605c08ae683fa_d1d129b9a8554b3 -- I, [2021-03-25T03:51:40.444733#3357] INFO --- [43d3f26b-4a66-4d78-a817-51cd935f0975] Completed 500 Internal Server Error in 30025ms F, [2021-03-25T03:51:40.445191#3357]FATAL --- [43d3f26b-4a66-4d78-a817-51cd935f0975] F, [2021-03-25T03:51:40.445228#3357] FATAL --- [43d3f26b-4a66-4d78-a817-51cd935f0975] Net::OpenTimeout(execution expired): F, [2021-03-25T03:51:40.445259#3357] FATAL --- [43d3f26b-4a66-4d78-a817-51cd935f0975] F, [2021-03-25T03:51:40.445284#3357]FATAL --- [43d3f26b-4a66-4d78-a817-51cd935f0975]app/controllers/quiry_controller.rb:23:in`thanks'

config/environments/production.rb

< preleukemia > < code > to - to vent our frustration - ~ : Omitted config.action_mailer.raise_delivery_errors=true config.action_mailer.default_url_options={:host=>'Public IP'} config.action_mailer.delivery_method=: smtp config.action_mailer.smtp_settings={ port:587, address: "smtp.gmail.com", domain: "gmail.com", user_name:ENV["SMTP_USERNAME"], password:ENV["SMTP_PASSWORD", authentication: "plain", enable_starttls_auto:true, }

ruby-on-rails aws amazon-ec2

2022-09-30 19:42

1 Answers

Because of the Timeout error, it is estimated that the port used by SMTP is not empty.What is the security group setting for EC2?--sugumura

As you pointed out, the outbound rules of the security group were set incorrectly.I added port number 587 and it was resolved.Thank you for your advice -- amaama

-- This post is to quote a comment to a question that was resolved in the comment.


2022-09-30 19:42

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.