Skip to content

Commit

Permalink
Generate mailer message id to fix spam issue
Browse files Browse the repository at this point in the history
  • Loading branch information
v9n committed Dec 31, 2019
1 parent 765d536 commit ae99d4f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# frozen_string_literal: true

class ApplicationMailer < ActionMailer::Base
# TODO: Remove hard code domain
# RFC 2822 requires that message-id match the from domain
# We're using SendGrid and the from domain is convert into [sendgrid-id]-[our-selected-subdomain]
DOMAIN = Rails.application.config.action_mailer.smtp_settings[:from].split("@").last
default(from: Rails.application.config.action_mailer.smtp_settings[:from],
'Message-ID' => -> { "#{Digest::SHA2.hexdigest(Time.now.to_i.to_s)}@noty.im" })
reply_to: 'hello@noty.im',
'Message-ID' => -> { "#{Digest::SHA2.hexdigest(Time.now.to_i.to_s)}@#{DOMAIN}" })

layout 'mailer'
end
2 changes: 1 addition & 1 deletion config/initializers/smtp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Rails.application.config.action_mailer.smtp_settings = {
authentication: :plain,
address: ENV['SMTP_ADDRESS'] || Rails.application.credentials[:SMTP_ADDRESS],
from: ENV.fetch('SMTP_FROM', 'oncall@alert.noty.im'),
from: ENV.fetch('SMTP_FROM', 'oncall@em4957.alert.noty.im'),
port: 587,
domain: ENV['SMTP_DOMAIN'] || Rails.application.credentials[:SMTP_DOMAIN],
user_name: ENV['SMTP_USER_NAME'] || Rails.application.credentials[:SMTP_USER_NAME],
Expand Down

0 comments on commit ae99d4f

Please sign in to comment.