Django-Mailer won’t stop sending emails

django

I set up Django Mailer and added the two commands to the crontab:

* * * * *      root     python /srv/www/cpm/manage.py send_mail >> /srv/www/cpm/cron_mail.log
0,20,40 * * * * root     python /srv/www/cpm//manage.py retry_deferred >> /srv/www/cpm/cron_mail_deferred.log

CPM is the directory that holds my Django project.

After restarting cron I fired up my Django project and clicked a link that puts around 600 emails onto the Django Mailer queue. The cron command picked up the queued messages and dutifully started sending the emails.

Each email is addressed to me for now for testing purposes. As expected, emails started pouring in.

However, after about 30 emails, I wanted to stop sending the emails as I wanted to make some changes, and start the process over again (I'm testing the app right now). I went into MySQL and deleted all the records in the django_mailer_queuedmessages table, thinking that will stop any further emails.

The emails kept coming.

I then deleted all the records in django_mailer_messages table, hoping that would stop the emails.

The emails kept coming!

I then deleted all records in every table that starts with django_mailer... and also commented out the crontab lines that have django-mailer in them (the two up above) and restarted cron.

The emails are STILL coming!!

What the heck!? How are they still being sent? Interestingly, each email states that it was sent at the time I clicked Send All Emails (about an hour ago now) and not when they arrived in my inbox. So, I'm not really sure what is going on or how to stop this onslaught of emails!

Hey look, another email just arrived

EDIT 1

I route all my email through my Google Apps Business email account. I simply connect to Gmail in my Python code in the standard way…

EDIT 2

It stopped… finally. I ended up sending a kill signal to the two processes that had started the cron commands. The only thing I can think that happened is that the django_mailer had stored all the emails in memory and was sending them from there. I had thought that django-mailer would pick an email off the queue (its own queue model), send it, then get the next message. This did not seem to be the case since I could delete the entire queue and messages were still sending. Clearly they existed somewhere else other than the queue stored in the MySQL database.

Kind of confusing…

Best Answer

Three step solution:

  1. Remove the entries from your crontab
    I don't know if it's still firing off an email every 60 seconds or not, but remove or comment these lines out so we're sure new mail isn't getting injected.

  2. Dump your mail queue
    …in whatever way is appropriate for your MTA software (since you don't specify your MTA I can't be more specific). This should get rid of any mail waiting to be sent (you may have a substantial backlog)

  3. Test manually and observe your system's behavior This will let you determine what happened, and how to prevent it from happening in the future.

Related Topic