Search code examples
ruby-on-railsgmailactionmailercontact-form

why i did'nt received all the mails from my rails5 application?


I deployed a rails5 web site with a contact form. I used action-mailer and gmail to send me the contact form (by my gmail account). I have 2-step verification with application password on my google account. The problem is that most of the time that works well but sometimes i didn't receive the mail. I think that's coming from Google, because if it was from my code why did i receive them most of the time. I hope someone has an idea. I have a second question is this syntax to call credentials from my action-mailer config is good?

    address:              'smtp.gmail.com',
    port:                 587,
    domain:               'domain.com',
    user_name:            ['Rails.application.credentials.dig(:production, :GMAIL_USER_NAME)'],
    password:             ['Rails.application.credentials.dig(:production, :GMAIL_PASSWORD)'],
    authentication:       'plain',
    enable_starttls_auto: true  } 

in my credentials.yml.enc :

    GMAIL_USER_NAME: [email protected]
    GMAIL_PASWORD: applicationgmailpassword

Solution

  • Because you are receiving some emails, I think you are right that the issue is with Google, not your application.

    Are they appearing in your spam folder?

    You could try switching to something like Mailgun. Try this tutorial: https://www.leemunroe.com/send-automated-email-ruby-rails-mailgun/

    As to your second question, I think you need to reformat.

    How to structure your credentials.yml.enc file:

    # no need to specify between environments
    # no need to capitalize
    gmail_user_name: [email protected]
    gmail_password: thisIsNotMyRealPassword
    

    Then to call these variables:

    Rails.application.credentials.gmail_user_name
    Rails.application.credentials.gmail_password
    

    So, in your ActionMailer config file, you should do this:

      ...
      user_name: Rails.application.credentials.gmail_user_name,
      password: Rails.application.credentials.gmail_password,
      ...