def __init__(self, msa, mail_list_url, mda_domain, list_subject_prefix=None): self.msa = msa # Relay: relay = DovecotLdaRelay(config['LDA']['dovecot_path'], timeout=10.0) # Queue: #env_db = shelve.open('envelope') #meta_db = shelve.open('meta') #storage = DictStorage(env_db, meta_db) # !!! replace with DiskStorage! (installed via pip install python-slimta-diskstorage) storage = DiskStorage(config['MDA']['ds_env'], config['MDA']['ds_meta']) self.queue = Queue( storage, relay) # no backoff - just fail local delivery immediately self.queue.start() # Headers: self.queue.add_policy(AddDateHeader()) self.queue.add_policy(AddMessageIdHeader()) self.queue.add_policy(AddReceivedHeader()) # Mailing List: self.queue.add_policy( MailingListDistribution(self.msa, mail_list_url, mda_domain, list_subject_prefix)) # SpamAssassin: #self.queue.add_policy(SpamAssassin()) # Edge: #tls_args = {'keyfile': '/home/jmcaine/dev/temp/slimta/tls/key.pem', 'certfile': '/home/jmcaine/dev/temp/slimta/tls/certificate.pem'} -- gone, see https://docs.slimta.org/en/latest/blog/2016-11-14.html ssl = SSLContext(PROTOCOL_SSLv23) ssl.load_cert_chain(config['SSL']['certificate_path'], config['SSL']['key_path']) self.edge = SmtpEdge(('0.0.0.0', 25), self.queue, validator_class=MDA_Validators, hostname=mda_domain, context=ssl) self.edge.start()
def test_raise_error(self): m = DovecotLdaRelay() with self.assertRaises(TransientRelayError): m.raise_error(m.EX_TEMPFAIL, 'message', '') with self.assertRaises(PermanentRelayError): m.raise_error(13, 'message', '')
def test_extra_args(self): m = DovecotLdaRelay(extra_args=['-t', 'test']) self.assertEquals(['-t', 'test'], m.args[-2:])
def _start_relay(self, name, options=None): if name in self.relays: return self.relays[name] if not options: options = getattr(self.cfg.relay, name) new_relay = None if options.type == 'mx': from slimta.relay.smtp.mx import MxSmtpRelay from .helpers import fill_hostname_template kwargs = {} kwargs['connect_timeout'] = options.get('connect_timeout', 30) kwargs['command_timeout'] = options.get('command_timeout', 30) kwargs['data_timeout'] = options.get('data_timeout', 60) kwargs['idle_timeout'] = options.get('idle_timeout', 10) kwargs['pool_size'] = options.get('concurrent_connections', 5) kwargs['ehlo_as'] = fill_hostname_template(options.ehlo_as) kwargs['context'] = self._get_client_ssl_context(options.tls) if options.ipv4_only: kwargs['socket_creator'] = build_ipv4_socket_creator([25]) new_relay = MxSmtpRelay(**kwargs) if 'force_mx' in options: for domain, dest in options.force_mx: new_relay.force_mx(domain, dest) elif options.type == 'static': from slimta.relay.smtp.static import StaticSmtpRelay from .helpers import fill_hostname_template, get_relay_credentials kwargs = {} kwargs['host'] = options.host kwargs['port'] = options.get('port', 25) kwargs['connect_timeout'] = options.get('connect_timeout', 30) kwargs['command_timeout'] = options.get('command_timeout', 30) kwargs['data_timeout'] = options.get('data_timeout', 60) kwargs['idle_timeout'] = options.get('idle_timeout', 10) kwargs['pool_size'] = options.get('concurrent_connections', 5) kwargs['ehlo_as'] = fill_hostname_template(options.ehlo_as) kwargs['context'] = self._get_client_ssl_context(options.tls) if 'credentials' in options: credentials = get_relay_credentials(options.credentials) kwargs['credentials'] = credentials if options.ipv4_only: kwargs['socket_creator'] = \ build_ipv4_socket_creator([kwargs['port']]) new_relay = StaticSmtpRelay(**kwargs) elif options.type == 'lmtp': from slimta.relay.smtp.static import StaticLmtpRelay from .helpers import fill_hostname_template, get_relay_credentials kwargs = {} kwargs['host'] = options.get('host', 'localhost') kwargs['port'] = options.get('port', 24) kwargs['connect_timeout'] = options.get('connect_timeout', 30) kwargs['command_timeout'] = options.get('command_timeout', 30) kwargs['data_timeout'] = options.get('data_timeout', 60) kwargs['idle_timeout'] = options.get('idle_timeout', 10) kwargs['pool_size'] = options.get('concurrent_connections', 5) kwargs['ehlo_as'] = fill_hostname_template(options.ehlo_as) kwargs['context'] = self._get_client_ssl_context(options.tls) if 'credentials' in options: credentials = get_relay_credentials(options.credentials) kwargs['credentials'] = credentials if options.ipv4_only: kwargs['socket_creator'] = \ build_ipv4_socket_creator([kwargs['port']]) new_relay = StaticLmtpRelay(**kwargs) elif options.type == 'http': from slimta.relay.http import HttpRelay from .helpers import fill_hostname_template kwargs = {} kwargs['ehlo_as'] = fill_hostname_template(options.ehlo_as) kwargs['timeout'] = options.get('timeout', 60) kwargs['idle_timeout'] = options.get('idle_timeout', 10) kwargs['context'] = self._get_client_ssl_context(options.tls) new_relay = HttpRelay(options.url, **kwargs) elif options.type == 'blackhole': from slimta.relay.blackhole import BlackholeRelay new_relay = BlackholeRelay() elif options.type == 'pipe': from slimta.relay.pipe import PipeRelay new_relay = PipeRelay(options.args) elif options.type == 'maildrop': from slimta.relay.pipe import MaildropRelay path = options.path new_relay = MaildropRelay(path) elif options.type == 'dovecot': from slimta.relay.pipe import DovecotLdaRelay path = options.path new_relay = DovecotLdaRelay(path) elif options.type == 'custom': new_relay = custom_factory(options) else: msg = 'relay type does not exist: '+options.type raise ConfigValidationError(msg) self.relays[name] = new_relay return new_relay