Search code examples
rubygmailactionmailerruby-on-rails-6

Rails ActionMailer mail's always go to spam


I configured mailing as below:

config.action_mailer.smtp_settings = {
   address: 'smtp.gmail.com',
   domain: 'gmail.com',
   port: 587,
   user_name: ENV['EMAIL_USERNAME'],
   password: ENV['EMAIL_PASSWORD'],
   authentication: 'plain'
}

Moreover, my from value matches the user_name.

Despite that, all my emails goes to spam, is there a way to avoid this behaviour?


Solution

  • Email is complicated, and I highly recommend using a service like SendGrid or MailGun to avoid some of the complexities, since it reduces the chance of you messing something up.

    That said, you're going to have issues sending email as gmail because you don't have the gmail domain (obviously, google owns it), so your message-ID is going to show that the domain that the email is coming from and the domain in the message-ID don't match, which will trigger most spam filters. If you own a domain, you can use that and send the email from there, which will make those line up.

    This might help: Set the Message-ID mail header in Rails3 / ActionMailer

    This also feels relevant: https://www.mailgun.com/blog/tips-tricks-avoiding-gmail-spam-filtering-when-using-ruby-on-rails-action-mailer/