Created
August 22, 2014 14:36
-
-
Save pete2786/1ddf0fec586731866e96 to your computer and use it in GitHub Desktop.
Module can included in a mailer to help warmup a new email provider on a static IP. This code was written for a transition from sendgrid to mailgun for a mailer which handled about 200k emails/day. The constants are set to transition from 100k/day to 3m/day with a 25% daily increase.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module mail_provider_warmup | |
DAILY_INCREASE_RATE = 1.25 # 25% | |
INITIAL_MAIL_VOLUME = 100000 | |
FINAL_MAIL_TARGET = 3000000.0 | |
WARMUP_START_DATE = Date.new(2014,7,24) | |
PROVIDER_FROM = :sendgrid | |
PROVIDER_TO = :mailgun | |
#selected_provider = self.class.select_provider(rand) | |
def self.select_provider(random) | |
return :PROVIDER_FROM if Date.today < WARMUP_START_DATE | |
random < provider_probability ? PROVIDER_FROM : PROVIDER_TO | |
end | |
def self.provider_probability | |
current_daily_mail_volume(days_since_warmup_start).to_f / FINAL_MAIL_TARGET | |
end | |
def self.current_daily_mail_volume(day) | |
return INITIAL_MAIL_VOLUME if day < 0 | |
INITIAL_MAIL_VOLUME * (DAILY_INCREASE_RATE ** day) | |
end | |
def self.days_since_warmup_start | |
(Date.today.to_date - WARMUP_START_DATE.to_date).to_i | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The expectation is that your application has implemented a provider input which can be used to set up your mailer. Read this article from the RailsApps team to learn more about the options you have for email service providers: http://railsapps.github.io/rails-send-email.html.
Sendgrid has good documentation about warming up an IP and why it is important: https://sendgrid.com/docs/User_Guide/warming_up.html.