Reputation: 148
Client's website is built in Rails 3 and hosted on Heroku, and accepts form submissions which are sent via rails mailers. They are receiving duplicates of emails. I'm unable to replicate the issue in my development environment.
Mail is sent via a gmail account registered to their domain with a standard rails mailer:
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "clientdomain.com",
:user_name => "[email protected]",
:password => "password",
:authentication => "plain",
:enable_starttls_auto => true
}
and
(gather data)
mail(:to => "[email protected]", :subject => "Form Submittal", :from => @email)
Duplicates are not necessarily sent instantly, as their delivery varies from 1 minute to over 3 hours after the original.
In some cases HTML characters are replaced with entities.
Here's an example:
From: [email protected]
> Subject: Form Submittal
> Date: December 14, 2012 10:38:18 PM EST
> To: [email protected]
>=20
> Form Submittal
>=20
> Name: Potential Lead
>=20
> Phone: 1234567890
>=20
> Email: [email protected]
>=20
> Message: Hi my names Some I'm from tennesse and I'd really like to =
> get info on your service thank you for all your help!!!
>=20
And duplicate:
> From: [email protected]
> Subject: Form Submittal
> Date: December 15, 2012 1:46:54 AM EST
> To: [email protected]
>=20
> Form Submittal
>=20
> Name: Potential Lead
>=20
> Phone: 1234567890
>=20
> Email: [email protected]
>=20
> Message: Hi my names Some I%27m from tennesse and I%27d really like =
> to get info on your service thank you for all your help%21%21%21
>=20
I was tempted to think the form was just being submitted twice, however the unlikeliness of submitting the exact same input after 3 hours, coupled with the sheer volume of dupes (60-75% reported at times, but never 100%) make me highly skeptical of that.
I also found a gist about duplicate issues which instructed me to override a default setting with this:
config.action_mailer.sendmail_settings = {
:arguments => '-i'
}
...to no beneficial result.
My question, if not obvious: how to stop rails from sending duplicate emails?
Upvotes: 2
Views: 893
Reputation: 1805
For anyone who gets here from google with same problem, here is the solution:
don't use .deliver
if you use Delayed Job to schedule mailing as originally stated here https://stackoverflow.com/a/13000167/1870446 and here https://github.com/collectiveidea/delayed_job#rails-3-mailers
So, instead of UserMailer.delay.some_mail.deliver
you should use UserMailer.delay.some_mail
. Cheers!
Upvotes: 1