You are here: Home / Documentation / How To's / External Method to change SMTP servers on all sites in a Zope

External Method to change SMTP servers on all sites in a Zope

by nguyen — published Nov 08, 2012 08:35 AM, last modified Aug 16, 2016 10:50 AM
In ZMI add an External Method (specify "change_smtp_servers" for all the values) after placing this file into your $INSTANCE/parts/instance/Extensions or $INSTANCE/parts/clientX/Extensions directory. This doesn't work as a Script (Python) because of restricted Python. Check the current source at

HTML icon — HTML, 1 KB (1814 bytes)

File contents

from Products.CMFPlone.Portal import PloneSite
from OFS.Folder import Folder


def do_site(site, item, change, out):
    mh = site.MailHost
    smtp = getattr(mh, 'smtp_host', None)
    if USE_HTML:
        if smtp != NEW_SMTP:
            out.append("<b>Plone site '%s' has <a href='%s'>smtp %s</a></b>" % (item, mh.absolute_url()+'/manage_main', smtp))
            out.append("Plone site '%s' has smtp %s" % (item, smtp))
        out.append("Plone site '%s' has smtp %s" % (item, smtp))
    if change == '1' and smtp and smtp != NEW_SMTP:
        mh.smtp_host = NEW_SMTP
        smtp_new = getattr(mh, 'smtp_host', None)
        out.append("   changed to smtp %s" % (smtp_new))
    return out

def change_smtp_servers(self, change=0):
    """ Changes the SMTP server of all the contained Plone sites. """
    out = []
    if USE_HTML:
    if change == 0:
        out.append('To change the SMTP server to %s, specify ?change=1 in the URL' % NEW_SMTP)
    for itemTuple in self.items():
        (item, itemType) = itemTuple
        if isinstance(itemType, PloneSite):
            site = getattr(self, item)
            out = do_site(site, item, change, out)
        elif isinstance(itemType, Folder):
            folder = getattr(self, item)
            for folderItemTuple in folder.items():
                (folderItem, folderItemType) = folderItemTuple
                if isinstance(folderItemType, PloneSite):
                    site = getattr(folder, folderItem)
                    out = do_site(site, folderItem, change, out)
    if USE_HTML:
    if USE_HTML:
        return "<br>".join(out)
        return "\n".join(out)