3

I send email from my domain using postfix without any issue. The problem is that when I send same email using a Rails application with same sender address, the message goes to spam folder in Gmail. I've tested it with and without Message-ID option in the mailer class:

default "Message-ID" => "#{Digest::SHA2.hexdigest(Time.now.to_i.to_s)}@mydomail.com"

This is my SMTP configurations:

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
    address:                 "127.0.0.1",
    port:                    25,
    enable_starttls_auto:    false
}
config.action_mailer.perform_deliveries = true

What configuration option I've missed that caused my emails to go to the spam folder?

Aref Aslani
  • 1,560
  • 13
  • 27
  • Could you include all the ActionMailer configuration you have done? Do you think that following this configurations would help as nobody there experienced this problem? Why are you using port 25 instead of 587? Why did you disable tls auto? Are you sending email with black carbon copies? Thanks http://stackoverflow.com/questions/6379950/gmail-smtp-with-rails-3#10795856 – Fabrizio Bertoglio Mar 14 '17 at 12:39
  • @FabrizioBertoglio: That was all the ActionMailer configuration that I did plus `config.action_mailer.perform_caching = false`. I don't have any idea what is the difference between port 25 and 587 and why I set auto tls to true. Is it possible that this is the cause of spamming outgoing messages? – Aref Aslani Mar 14 '17 at 16:00
  • how is the `config.mailer_sender = 'noreply@truhawk.com'` in devise.rb, `default_url_options`, did you set content type in your environment.rb `ActionMailer::Base.default_content_type = "text/html"`? I am attaching you some links. http://stackoverflow.com/questions/8186584/how-do-i-set-up-email-confirmation-with-devise http://www.tutorialspoint.com/ruby-on-rails/rails-send-email.htm http://stackoverflow.com/questions/8186584/how-do-i-set-up-email-confirmation-with-devise – Fabrizio Bertoglio Mar 14 '17 at 17:42
  • Problem solved. That was an issue by Postfix and SPF record in DNS. Thanks. – Aref Aslani Mar 14 '17 at 19:00

2 Answers2

3

It was a Postfix + DNS problem. Emails goes to spam folder in Gmail that means everything is ok with Rails. After I checked the Postfix main.cf noticed that the host value was srv1.example.com and SPF record in DNS was example.com.

Aref Aslani
  • 1,560
  • 13
  • 27
1

This is fairly standard these days. Spammers can easily set up local SMTP servers to send out millions of emails a day much more easily and cheaply than buying dedicated IP addresses to send these emails from.

As a result, quite often emails sent from localhost will end up in spam by default.

You can overcome this fairly easily by using something like SendGrid, MailGun or Amazon SES.

Max Woolf
  • 3,988
  • 1
  • 26
  • 39