by Sumit Chachra on July 10, 2010
Its usually good to sandbox your QA / staging environments so that they don’t shoot out emails to real email addresses (say you’ve made a copy of your production database). Django 1.2 and their email backends make it really easy to do so.
Here’s a testing email backend I wrote. Simply drop in a email address associated with the DEFAULT_TO_EMAIL setting in your settings.py. Also set the EMAIL_BACKEND in settings.py to the class below.
This also takes care of cases where in your code you’re sending a “mass mail” (using send_mass_mail), it’ll only send one out.
from django.core.mail.backends.smtp import EmailBackend
class TestingEmailBackend(EmailBackend):
"""
Used in dev and qa
"""
def send_messages(self, email_messages):
"""
Overrides the to email address. Also if there are tons of messages being sent out then it reduces them to
1 message.
"""
if len(email_messages) > 1:
email_messages = (email_messages[0],)
email_messages[0].to = [django_settings.DEFAULT_TO_EMAIL,]
super(TestingEmailBackend, self).send_messages(email_messages)by Sumit Chachra on March 4, 2010
So I have a Wordpress MU setup where we’re hosting a bunch of sites/blogs (email me at sumit AT tivixlabs.com if you’re interested in one).
As with all my Django webapps I wanted to replicate all the sites on qa for testing purposes (so that we’re not messing production sites with plugin / wordpress upgrades etc.). The problem is the qa site runs on a different domain (say domain2.com) than the production MU install (say domain1.com).
Since my stores the domain in 1 file (easy to fix) and a bunch of db tables, the easy solution is to:
- Make a copy of entire wordpress directory and put the correct domain in wp-config.php in this line: define(‘DOMAIN_CURRENT_SITE’, ‘domain2.com’ );
- Take a dump of your existing MU installs database. Open that dump file and do a replace of all “domain1.com” strings with “domain2.com”. Next do a replace of “domain1″ with “domain2″. Source this new dump into the new database for the new MU instance.
Thats it. These 2 steps should be it. Your MU site should now run like your old one, but at domain2.com and all existing sites/blogs will run at old-sub-domain.domain2.com too!