Sign inDemoInstall


Package Overview
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies



Used for integration testing with Plone




collective.MockMailHost enables integration testing of email functionality from Plone_. Simply add this egg to your [test] runner section, and install this product through your Layer or TestCase.

Note THIS IS FOR TESTING PURPOSE ONLY, do not use this product on your running Plone site. It replaces the standard MailHost with a Mock MailHost that you can poke at to check email content and recipients.

Has been tested with Plone 4 but should also work with earlier versions.


Example how to integrate collective.MockMailHost to your testing setup based on Add the package to your extras_requires section in your package's file, so buildout will automatically download the package for you.::

        'test': [

Your test layer setup could look like this example below::

from import helpers, layers
from plone.testing import z2

class MyLayer(helpers.PloneSandboxLayer):
    defaultBases = (layers.PLONE_FIXTURE, )

    def setUpZope(self, app, configurationContext):
        # Load zcml
        import collective.MockMailHost

        # Install product and call its initialize() function
        z2.installProduct(app, 'collective.MockMailHost')

        # Note: you can skip this if my.product is not a Zope 2-style
        # product, i.e. it is not in the Products.* namespace and it
        # does not have a <five:registerPackage /> directive in its
        # configure.zcml.

    def tearDownZope(self, app):
        # Uninstall product
        z2.uninstallProduct(app, 'collective.MockMailHost')

        # Note: Again, you can skip this if my.product is not a Zope 2-
        # style product

    def setUpPloneSite(self, portal):
        helpers.quickInstallProduct(portal, 'collective.MockMailHost')

        helpers.applyProfile(portal, 'collective.MockMailHost:default')

MY_FIXTURE = MyLayer()

.. _Plone: ..

Using a member-posting forum

>>> from Products.CMFCore.utils import getToolByName
>>> from Products.MailHost.interfaces import IMailHost
>>> from zope.component import getUtility

>>> app = layer['app']
>>> portal = layer['portal']

Test starting conversations, replying and modifying comments in a default member-posting forum.

Let us log all exceptions, which is useful for debugging. Also, clear portlet slots, to make the test browser less confused by things like the recent portlet and the navtree.

>>> portal.error_log._ignored_exceptions = ()
>>> portal.left_slots = portal.right_slots = []
>>> workflow = portal.portal_workflow

Validate mailhost replacement

>>> portal.MailHost
<MockMailHost at ...>

>>> getToolByName(portal, 'MailHost')
<MockMailHost at ...>

>>> getUtility(IMailHost)
<MockMailHost at ...>

Send email

>>> to_ = ""
>>> from_ = ""
>>> msg = """
... Dear Sir:
... Thank you"""
>>> portal.MailHost.send(msg, to_, from_)
>>> len(portal.MailHost.messages)
>>> 'To:' in portal.MailHost.messages[0]
>>> 'From:' in portal.MailHost.messages[0]
>>> 'Dear Sir:' in portal.MailHost.messages[0]
>>> portal.MailHost.reset()
>>> len(portal.MailHost.messages)


2.0.0 (2018-11-06)

Breaking changes:

  • Do not depend on old SecureMailHost any longer. [pbauer]

New features:

  • Python 3 support. [pbauer]

1.1.0 (2018-06-27)

  • Fix import location, Globals has been removed. [gforcada]

  • Rework tests setup. [gforcada]

1.0 (2016-01-25)

  • Fix MIMEText compatibility (broken since 0.9). [jone]

0.9 (2015-07-10)

  • Clean up msg before sending. Otherwise Plone self registration email does not work [sureshvv]

0.8 (2015-06-13)

  • Add browser view for functional testing [Casecarsid]

0.7 (2013-07-05)

  • MANIFEST [sureshvv]

0.6 (2013-07-03)

  • Track msg_type also. [sureshvv]

  • Behave more like collective.testcaselayer's MockMailHost. [saily]

  • Documentation updates [saily]

0.5 - 2012-09-25

  • Remove ZopeSkel and Paster dependency from [saily]

  • Moved to github and changed to README.rst, links in [saily]

  • Allow multiple paramters for send and secureSend method in MockMailHost class. [saily]

0.4 (2011-05-17)

  • Register MockMailHost in SiteManager to get MockMailHost when using getToolByName(context, 'MailHost') or getUtility(IMailHost). [saily]

  • Inherit from MailHost instead of SimpleItem [saily]

  • Implement the secureSend method [saily]

0.3 (2011-04-04)

  • Add **kwargs to MockMailHost's send method to support mto, mfrom, ... keyword arguments as default MailHost does. [saily]

  • Added file for generic setup various handlers [sureshvv]

0.2 (2010-05-21)

  • Added tests [sureshvv]

0.1 (2010-05-16)

  • Initial release [sureshvv]



Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.


Related posts

SocketSocket SOC 2 Logo


  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc