Closed n11c closed 6 years ago
Closing this -- reopen if passing a function as ehlo_as
(as described above) won't work for you.
Thanks for the feedback @icgood
I've been a bit too fast submitting this PR.
The use case is a bit more complicated.
The source IP and EHLO are determined before calling attempt()
and we wanted to be able to pass them dynamically for each attempt. Existing mechanisms (socket_creator and ehlo_as function) don't quite fulfil our needs.
We've actually already sub-classed the MxSmtpRelay to override new_static_relay() and other reasons.
The idea here was to avoid having to copy-paste its attempt()
just to achieve this, by adding a way to pass along kwargs to the actual static relay creator.
But after reviewing our code, it turns out that it actually requires even more changes than what I submitted (eg. kwargs on _attempt()
as well to be able to get relay policies to apply).
So I agree that it may not be a good candidate for an upstream merge.
I'd be happy to get your input on this if you find the time (see example code below). But in any case, feel free to close this PR as wontmerge.
class BoundMXRelay(MxSmtpRelay):
def new_static_relay(
self, destination, port, source_ip=None, ehlo_as=None):
return SourceBoundStaticSmtpRelay(
source_ip, destination, port=port, ehlo_as=ehlo_as,
**self._client_kwargs)
def _attempt(self, envelope, attempts, **kwargs):
self._run_policies(envelope)
return self.attempt(envelope, attempts, **kwargs)
def attempt(self, envelope, attempts, source_ip=None, ehlo_as=None):
return super().attempt(
envelope, attempts, source_ip=source_ip, ehlo_as=ehlo_as)
Our use case is the following: source IP / EHLO to use for outbound connection is determined for each attempt, so we needed a way to pass this on to create a source-bound relay.
I found this to be the less invasive way to handle this.
Let me know what you think.