def setUp(self): from zope.sendmail.queue import QueueProcessorThread self.md = MaildirStub('/foo/bar/baz') self.thread = QueueProcessorThread() self.thread.setMaildir(self.md) self.mailer = MailerStub() self.thread.setMailer(self.mailer) self.thread.log = LoggerStub() self.dir = mkdtemp()
def createQueuedDelivery(): delivery = QueuedMailDelivery(queuePath) if permission is not None: delivery = _assertPermission(permission, IMailDelivery, delivery) handler('registerUtility', delivery, IMailDelivery, name) mailerObject = queryUtility(IMailer, mailer) if mailerObject is None: raise ConfigurationError("Mailer %r is not defined" % mailer) if processorThread: thread = QueueProcessorThread() thread.setMailer(mailerObject) thread.setQueuePath(queuePath) thread.start()
def create_emailUtilities(instance_id=None): '''Create the utilities to send the email messages :param str instance_id: The indentifier for the GroupServer instance :returns: ``None`` The :func:`create_emailUtilities` function loads the ``smtp`` section of the configuration of the instance specified by ``instance_id``. If no instance is specified then :func:`gs.config.getInstanceId` is used to determine the current instance. It then loads the following configuration options: * ``hostname`` * ``port`` * ``username`` * ``password`` * ``no_tls`` * ``force_tls`` * ``queuepath`` * ``processorthread`` * ``xverp`` If the XVERP option is ``True`` then :class:`gs.email.mailer.XVERPSMTPMailer` is registered as the utility used to connect to the SMTP host; otherwise :class:`zope.sendmail.mailer.SMTPMailer` is used. In either case the mailer is configured with the options in the config file.''' if not instance_id: instance_id = getInstanceId() config = Config(instance_id) config.set_schema('smtp', {'hostname': str, 'port': int, 'username': str, 'password': str, 'no_tls': bool_, 'force_tls': bool_, 'queuepath': str, 'processorthread': bool_, 'xverp': bool_}) smtpconfig = config.get('smtp', strict=False) name = '' for key in ('hostname', 'port', 'username', 'password', 'no_tls', 'force_tls'): name += '+%s+' % smtpconfig.get(key, None) gsm = getGlobalSiteManager() if not queryUtility(IMailer, 'gs.mailer.%s' % name): if smtpconfig.get('xverp', False): Mailer = XVERPSMTPMailer else: Mailer = SMTPMailer gsm.registerUtility( Mailer( hostname=smtpconfig.get('hostname', None), port=smtpconfig.get('port', None), username=smtpconfig.get('username', None), password=smtpconfig.get('password', None), no_tls=smtpconfig.get('no_tls', None), force_tls=smtpconfig.get('force_tls', None)), IMailer, name='gs.mailer.%s' % name) queuePath = smtpconfig.get('queuepath', '/tmp/mailqueue') if not queryUtility(IMailDelivery, name='gs.maildelivery'): delivery = QueuedMailDelivery(queuePath) gsm.registerUtility(delivery, IMailDelivery, name='gs.maildelivery') if smtpconfig.get('processorthread', True): mailerObject = getUtility(IMailer, 'gs.mailer.%s' % name) thread = QueueProcessorThread() thread.setMailer(mailerObject) thread.setQueuePath(queuePath) thread.start()