Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29758

Gmail not receiving ActionMailer Email

$
0
0

So I'm building my portfolio right now and I want to send an actual email to my gmail in development and production, using ActionMailer.

I have configured my development.rb in a way such that if a user enters the contact form, and submit it ActionMailer would send an email to my gmail account; problem is, my gmail shows no email coming from the contact form even though logs says that the email was sent successfully. Things I've tried:

  1. Change gmail setting to accept less secure apps
  2. Change smtp to sendmail
  3. moved the whole smtp/sendmail configs to dev/prod.rb instead of smtp.rb
  4. change gmail addresses

Funny thing is, it used to work both in prod & development env but after a couple of hours of not working on it, these stopped working. Please give me advise as far as how I can fix this.

development.rb

  # MAiler
  # Don't care if the mailer can't send.
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.default_url_options = { host:'localhost', port: '3000' }
  config.action_mailer.delivery_method = :sendmail
  #send email in dev mode
  config.action_mailer.perform_deliveries = true
  config.action_mailer.perform_caching = false
  config.action_mailer.raise_delivery_errors= true

  ActionMailer::Base.sendmail_settings = {
    address:              'smtp.gmail.com',
    port:                 587,
    domain:               'gmail.com',
    user_name:            ENV["GMAIL_EMAIL"],
    password:             ENV["GMAIL_PASSWORD"],
    authentication:       'plain',
    enable_starttls_auto: true  }

smtp.rb None at the moment, but used to be

  ActionMailer::Base.sendmail_settings = {
    address:              'smtp.gmail.com',
    port:                 587,
    domain:               'gmail.com',
    user_name:            ENV["GMAIL_EMAIL"],
    password:             ENV["GMAIL_PASSWORD"],
    authentication:       'plain',
    enable_starttls_auto: true  }

Production.rb

# MAiler
  # Don't care if the mailer can't send.
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.default_url_options = { host:'www.domainname.com' } #domainname hidden 
  config.action_mailer.delivery_method = :sendmail
  #send email in dev mode
  config.action_mailer.perform_deliveries = true
  config.action_mailer.perform_caching = false
  config.action_mailer.raise_delivery_errors= true
  # config.action_mailer.perform_caching = false

contact_mailer.rb

class ContactMailer < ApplicationMailer
  def contact_email(contact)
    @contact = contact
      # default from: "#{@contact.email}"
      mail(from: "#{@contact.email}", to: "email@gmail.com", subject: "#{@contact.subject}")
  end
end

.env

GMAIL_EMAIL=email.com
GMAIL_PASSWORD=#hiddenbcofsecurity

Any insights will be appreciated. Also if additional info is needed to let me know. Thanks.

EDIT: I will post the logs of what the terminal is showing upon submitting the form.

Development:

Started POST "/contacts" for ::1 at 2019-12-19 00:22:29 +0900
Processing by ContactsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"2UYC+mGR9c/S1obBYFyBxZ76vfXUQijnQsfz8C9BeqwgeUshNV/ARlHDLvaIVripK1sRTeuXjQGRg6n0+zKS4g==", "contact"=>{"full_name"=>"Bob Marley", "email"=>"bobmarley@nifty.com", "subject"=>"dev modde", "message"=>"hi"}, "commit"=>"SEND"}
   (0.5ms)  BEGIN
  ↳ app/controllers/contacts_controller.rb:8
  Contact Create (0.7ms)  INSERT INTO "contacts" ("full_name", "email", "message", "created_at", "updated_at", "subject") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id"  [["full_name", "Bob Marley"], ["email", "bobmarley@nifty.com"], ["message", "hi"], ["created_at", "2019-12-18 15:22:29.134945"], ["updated_at", "2019-12-18 15:22:29.134945"], ["subject", "dev modde"]]
  ↳ app/controllers/contacts_controller.rb:8
   (0.5ms)  COMMIT
  ↳ app/controllers/contacts_controller.rb:8
  Rendering contact_mailer/contact_email.html.erb within layouts/mailer
  Rendered contact_mailer/contact_email.html.erb within layouts/mailer (0.4ms)
ContactMailer#contact_email: processed outbound mail in 42.8ms
Sent mail to mygmail@gmail.com (34.0ms)
Date: Thu, 19 Dec 2019 00:22:29 +0900
From: bobmarley@nifty.com
To: mygmail@gmail.com
Message-ID: <5dfa44353062c_2c493fc67aa1acf4626e0@taiseis-mbp.lan.mail>
Subject: dev modde
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7b

it

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style>
      /* Email styles need to be inline */
    </style>
  </head>

  <body>
    hi
  </body>
</html>

Redirected to http://localhost:3000/projects
Completed 302 Found in 99ms (ActiveRecord: 1.7ms)

In production (heroku logs):

2019-12-18T15:26:07.321077+00:00 app[web.1]: I, [2019-12-18T15:26:07.320977 #4]  INFO -- : [775341a7-6c37-4b93-8b4a-65afaec7426f] Started POST "/contacts" for 14.11.35.130 at 2019-12-18 15:26:07 +0000
2019-12-18T15:26:07.322013+00:00 app[web.1]: I, [2019-12-18T15:26:07.321958 #4]  INFO -- : [775341a7-6c37-4b93-8b4a-65afaec7426f] Processing by ContactsController#create as HTML
2019-12-18T15:26:07.322129+00:00 app[web.1]: I, [2019-12-18T15:26:07.322076 #4]  INFO -- : [775341a7-6c37-4b93-8b4a-65afaec7426f]   Parameters: {"utf8"=>"✓", "authenticity_token"=>"QKe+3gNQhLKsvXoSisk4X40MZUg8+kCDB51wFKjTZr6FtyTHgAcN8HN6jwwLjpQyb/RR63R5GTYEIkFX5yKXww==", "contact"=>{"full_name"=>"Bob Marley", "email"=>"bobmarley@nifty.com", "subject"=>"prod mode", "message"=>"pro mode"}, "commit"=>"SEND"}
2019-12-18T15:26:07.325362+00:00 app[web.1]: D, [2019-12-18T15:26:07.325304 #4] DEBUG -- : [775341a7-6c37-4b93-8b4a-65afaec7426f]    (0.8ms)  BEGIN
2019-12-18T15:26:07.327780+00:00 app[web.1]: D, [2019-12-18T15:26:07.327723 #4] DEBUG -- : [775341a7-6c37-4b93-8b4a-65afaec7426f]   Contact Create (1.2ms)  INSERT INTO "contacts" ("full_name", "email", "message", "created_at", "updated_at", "subject") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id"  [["full_name", "Bob Marley"], ["email", "bobmarley@nifty.com"], ["message", "pro mode"], ["created_at", "2019-12-18 15:26:07.325667"], ["updated_at", "2019-12-18 15:26:07.325667"], ["subject", "prod mode"]]
2019-12-18T15:26:07.329643+00:00 app[web.1]: D, [2019-12-18T15:26:07.329591 #4] DEBUG -- : [775341a7-6c37-4b93-8b4a-65afaec7426f]    (1.6ms)  COMMIT
2019-12-18T15:26:07.333855+00:00 app[web.1]: I, [2019-12-18T15:26:07.333795 #4]  INFO -- : [775341a7-6c37-4b93-8b4a-65afaec7426f]   Rendering contact_mailer/contact_email.html.erb within layouts/mailer
2019-12-18T15:26:07.334327+00:00 app[web.1]: I, [2019-12-18T15:26:07.334271 #4]  INFO -- : [775341a7-6c37-4b93-8b4a-65afaec7426f]   Rendered contact_mailer/contact_email.html.erb within layouts/mailer (0.4ms)
2019-12-18T15:26:07.335088+00:00 app[web.1]: D, [2019-12-18T15:26:07.335025 #4] DEBUG -- : [775341a7-6c37-4b93-8b4a-65afaec7426f] ContactMailer#contact_email: processed outbound mail in 5.1ms
2019-12-18T15:26:07.338215+00:00 app[web.1]: **sh: 1: /usr/sbin/sendmail: not found**
2019-12-18T15:26:07.338580+00:00 app[web.1]: I, [2019-12-18T15:26:07.338497 #4]  INFO -- : [775341a7-6c37-4b93-8b4a-65afaec7426f] **Sent mail to mygmail@gmail.com** (3.3ms)
2019-12-18T15:26:07.338659+00:00 app[web.1]: D, [2019-12-18T15:26:07.338591 #4] DEBUG -- : [775341a7-6c37-4b93-8b4a-65afaec7426f] Date: Wed, 18 Dec 2019 15:26:07 +0000
2019-12-18T15:26:07.338661+00:00 app[web.1]: From: bobmarley@nifty.com
2019-12-18T15:26:07.338662+00:00 app[web.1]: To: mygmail@gmail.com
2019-12-18T15:26:07.338664+00:00 app[web.1]: Message-ID: <5dfa450f5202a_42b157c94faf411871@f450c424-ae43-4fd2-8009-51ce04ea4d9f.mail>
2019-12-18T15:26:07.338665+00:00 app[web.1]: Subject: prod mode
2019-12-18T15:26:07.338666+00:00 app[web.1]: Mime-Version: 1.0
2019-12-18T15:26:07.338667+00:00 app[web.1]: Content-Type: text/html;
2019-12-18T15:26:07.338669+00:00 app[web.1]: charset=UTF-8
2019-12-18T15:26:07.338670+00:00 app[web.1]: Content-Transfer-Encoding: 7bit
2019-12-18T15:26:07.338671+00:00 app[web.1]: 
2019-12-18T15:26:07.338672+00:00 app[web.1]: <!DOCTYPE html>
2019-12-18T15:26:07.338673+00:00 app[web.1]: <html>
2019-12-18T15:26:07.338674+00:00 app[web.1]: <head>
2019-12-18T15:26:07.338676+00:00 app[web.1]: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
2019-12-18T15:26:07.338677+00:00 app[web.1]: <style>
2019-12-18T15:26:07.338678+00:00 app[web.1]: /* Email styles need to be inline */
2019-12-18T15:26:07.338679+00:00 app[web.1]: </style>
2019-12-18T15:26:07.338680+00:00 app[web.1]: </head>
2019-12-18T15:26:07.338680+00:00 app[web.1]: 
2019-12-18T15:26:07.338681+00:00 app[web.1]: <body>
2019-12-18T15:26:07.338682+00:00 app[web.1]: pro mode
2019-12-18T15:26:07.338683+00:00 app[web.1]: </body>
2019-12-18T15:26:07.338684+00:00 app[web.1]: </html>
2019-12-18T15:26:07.338685+00:00 app[web.1]: 
2019-12-18T15:26:07.338964+00:00 app[web.1]: I, [2019-12-18T15:26:07.338914 #4]  INFO -- : [775341a7-6c37-4b93-8b4a-65afaec7426f] Redirected to mydomain

No errors were found aside from sh: 1: /usr/sbin/sendmail: not found which is weird because i added the sendmail gem and executed bundle install.


Viewing all articles
Browse latest Browse all 29758

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>