Skip to content. | Skip to navigation

Personal tools


You are here: Home / Blog / Debugging with MockMailHost

Debugging with MockMailHost

by Ross Patterson last modified May 12, 2008 08:16 PM
Using the mock MailHost on a real instance

I often find the need to debug user registration or other functionality that involves sending mail through the MailHost where I either don't want the mail to go out, or I want to intercept it for examination or both.  Using "zopectl debug" I replace the MailHost with a MockMailHost as follows::

>>> app.Plone._delObject('MailHost')
>>> from Products.PasswordResetTool.tests import utils
>>> mail_host = utils.MockMailHost('MailHost')
>>> app.Plone._setObject('MailHost', mail_host)
>>> app.Plone.MailHost
<MockMailHost at /Plone/MailHost>
>>> import transaction
>>> transaction.commit()

Then using PDBDebugMode or "zopectl debug" again, the messages sent through the MailHost can be examined as follows::

(Pdb) print self.MailHost.messages[-1]

I have long intended to build a package with a GenericSetup profile that will do this for me, but I wanted to get this out there for now.  Enjoy!

OpenID Login


IRC: rossp
Yahoo IM: patterson_ross
AIM: rosspatters
Skype: merpattersonnet

PO Box 7775 #10587
San Francisco, CA

+1 (415) 894-5323