简体   繁体   中英

Mailform works locally but not in production (Heroku, Rails)

Quick question, I am using the Mailform gem on my rails app. Submitting a contact form from my rails app WORKS LOCALLY but does not work in production (Heroku).

Using heroku logs --tails , I see that Heroku successfully sends the mail. However I do not receive it in my respective inbox, spam, junk etc. You can see below that Heroku says the mail was sent successfully:

2021-10-21T10:18:10.113426+00:00 app[web.1]: I, [2021-10-21T10:18:10.113404 #4]  INFO -- : [fc7bc81d-de05-43c8-8c0c-b0f865d3b385]   Parameters: {"authenticity_token"=>"AEQA5AFuDM1Z9kJkxIjONKSykC3byTzKiRIajUwBZJBa/ZGTQhm13NSOI3Gni+no1U2svV/PB1mRXDFct31ZXQ==", "contact"=>{"name"=>"Somes Name", "email"=>"username@gmail.com", "subject"=>"site test", "message"=>"This is a test email"}, "commit"=>"Send Message"}
2021-10-21T10:18:10.114201+00:00 app[web.1]: I, [2021-10-21T10:18:10.114166 #4]  INFO -- : [fc7bc81d-de05-43c8-8c0c-b0f865d3b385] Redirected to https://iliazolas.herokuapp.com/
2021-10-21T10:18:10.119363+00:00 app[web.1]: I, [2021-10-21T10:18:10.119311 #4]  INFO -- : [fc7bc81d-de05-43c8-8c0c-b0f865d3b385]   Rendering vendor/bundle/ruby/2.7.0/gems/mail_form-1.9.0/lib/mail_form/views/mail_form/contact.erb
2021-10-21T10:18:10.120596+00:00 app[web.1]: I, [2021-10-21T10:18:10.120551 #4]  INFO -- : [fc7bc81d-de05-43c8-8c0c-b0f865d3b385]   Rendered vendor/bundle/ruby/2.7.0/gems/mail_form-1.9.0/lib/mail_form/views/mail_form/contact.erb (Duration: 1.2ms | Allocations: 710)
2021-10-21T10:18:10.121033+00:00 app[web.1]: D, [2021-10-21T10:18:10.120974 #4] DEBUG -- : [fc7bc81d-de05-43c8-8c0c-b0f865d3b385] MailForm::Notifier#contact: processed outbound mail in 4.7ms
2021-10-21T10:18:10.285048+00:00 app[web.1]: I, [2021-10-21T10:18:10.284947 #4]  INFO -- : [fc7bc81d-de05-43c8-8c0c-b0f865d3b385] Delivered mail 61713e621dad0_494c09453@10e20764-9922-42fe-bc81-e7fd2761d078.mail (163.8ms)
2021-10-21T10:18:10.285081+00:00 app[web.1]: D, [2021-10-21T10:18:10.285045 #4] DEBUG -- : [fc7bc81d-de05-43c8-8c0c-b0f865d3b385] Date: Thu, 21 Oct 2021 10:18:10 +0000
2021-10-21T10:18:10.285081+00:00 app[web.1]: From: Ilia Zolas <username@gmail.com>
2021-10-21T10:18:10.285082+00:00 app[web.1]: To: username@gmail.com
2021-10-21T10:18:10.285082+00:00 app[web.1]: Message-ID: <61713e621dad0_494c09453@10e20764-9922-42fe-bc81-e7fd2761d078.mail>
2021-10-21T10:18:10.285082+00:00 app[web.1]: Subject: IZ Portfolio Contact Form
2021-10-21T10:18:10.285083+00:00 app[web.1]: Mime-Version: 1.0
2021-10-21T10:18:10.285083+00:00 app[web.1]: Content-Type: text/html;
2021-10-21T10:18:10.285083+00:00 app[web.1]: charset=UTF-8
2021-10-21T10:18:10.285084+00:00 app[web.1]: Content-Transfer-Encoding: 7bit
2021-10-21T10:18:10.285084+00:00 app[web.1]: 
2021-10-21T10:18:10.285084+00:00 app[web.1]: <h4 style="text-decoration:underline">IZ Portfolio Contact Form</h4>
2021-10-21T10:18:10.285085+00:00 app[web.1]: 
2021-10-21T10:18:10.285085+00:00 app[web.1]: 
2021-10-21T10:18:10.285085+00:00 app[web.1]: <p><b>Name:</b>
2021-10-21T10:18:10.285085+00:00 app[web.1]: Name</p>
2021-10-21T10:18:10.285085+00:00 app[web.1]: 
2021-10-21T10:18:10.285085+00:00 app[web.1]: <p><b>Subject:</b>
2021-10-21T10:18:10.285086+00:00 app[web.1]: site test</p>
2021-10-21T10:18:10.285086+00:00 app[web.1]: 
2021-10-21T10:18:10.285086+00:00 app[web.1]: <p><b>Email:</b>
2021-10-21T10:18:10.285086+00:00 app[web.1]: username@gmail.com</p>
2021-10-21T10:18:10.285086+00:00 app[web.1]: 
2021-10-21T10:18:10.285087+00:00 app[web.1]: <p><b>Message:</b>
2021-10-21T10:18:10.285087+00:00 app[web.1]: This is a test email</p>
2021-10-21T10:18:10.285087+00:00 app[web.1]: 
2021-10-21T10:18:10.285087+00:00 app[web.1]: 
2021-10-21T10:18:10.285102+00:00 app[web.1]: Message sent

Please note that I have replaced my actual email address with username@gmail and name for this post.

Also, I have set the relevant Google Account to allow access to less secure apps.

Here is my production environment for mailform:

  config.action_mailer_default_url_options = { host: 'https://www.iliazolas.herokuapp.com' }
  Rails.application.routes.default_url_options[:host] = 'https://www.iliazolas.herokuapp.com'
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = false
  config.action_mailer.default charset: 'utf-8'
  config.action_mailer.smtp_settings = {
  address: 'smtp.gmail.com',
  port: 587,
  domain: 'gmail.com',
  authentication: 'plain',
  enable_starttls_auto: true,
  user_name: ENV['GMAIL_USERNAME'],
  password: ENV['GMAIL_PASSWORD']
}

Does anyone have any thoughts on what I am doing wrong?

Thanks again for your time and effort!

So I logged back into my google account regarding the related gmail credentials. Turns out that google was still seeing my app's action as suspicious activity regardless of enabling access to less secure apps.

So all I did was notify google that the suspicious activity was from myself using the provided interface as well as change my account password and updated my .env file with the new password.

Then... all of a sudden... messages sent from the contact form on my site started to work.

Voila :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM