Search code examples
ruby-on-railsdelayactionmailer

Rails ActionMailer add a delay for few milliseconds before sending an email


Is there a way to achieve above at a single place, as we have lot of places to send email and can't change email sending calls to add a delay through out the application code base.

We just want to make sure that not more than X emails are being sent in 1 second.

We are using rails 2.3.5.

Thanks

EDIT

We are using Amazon SES for sending emails. Initially they allow 1 email per second. What happens if we send more than one emails per seconds. Would SES queue them or throw some exception?


Solution

    1. Make your mail sending logic async by using a job queue, for example delayed_job or resque
    2. Have a job processor that takes jobs from the queue and processes them, as such you can control the sending interval from the processor logic