Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catching a BadReply somewhere but not sure why #118

Closed
thestick613 opened this issue Nov 25, 2016 · 2 comments · Fixed by #169
Closed

Catching a BadReply somewhere but not sure why #118

thestick613 opened this issue Nov 25, 2016 · 2 comments · Fixed by #169

Comments

@thestick613
Copy link

I'm catching a SmtpTransientRelayError as e, but in e.reply.message i've got the following text: 4.3.0 Bad SMTP reply from server.. I want to find out what's happening, but i can't find out when this is raised, because BadReply is always initialized with some other message. There doesn't seem to be a message here, and i can't find it once the exception is raised.

I'm on slitma3.

@thestick613
Copy link
Author

I've been able to pinpoint this further down. When you instantiate a BadReply with some data, the data attribute is empty when the exception is raised. I'm going to post some code which will replicate this.

@evowise
Copy link

evowise commented Feb 2, 2017

An example to reproduce it is when a server sends a SMTP response without a status code.

This is an example caught in a PowerMTA server:
"SMTP protocol failure: syntax error: 3-digit code not found; 4.7.0 [IPTS04] Messages from x.x.x.x temporarily deferred due to user complaints - 4.16.55.1; see https://help.yahoo.com/kb/postmaster/SLN3434.html by mta5.am0.yahoodns.net (y.y.y.y) while connected from ...."

And this is what is reported by slimta: "4.3.0 Bad SMTP reply from server."

I'll post 2 minimalist pieces of code to reproduce it, a rely and an edge:

from slimta.relay.smtp import SmtpTransientRelayError

from slimta.relay.smtp.static import StaticSmtpRelay
from slimta.envelope import Envelope

relay = StaticSmtpRelay(host="localhost", port=25, pool_size=1)

try:
    delivery_results = relay.attempt(Envelope(), 0)
except SmtpTransientRelayError as e:
    print("I have encountered a %s, with the message '%s'" %  (type(e).__name__, e))
    print("Exact reply code %s message %s" % (repr(e.reply.code), repr(e.reply.message)))

and

from slimta.edge.smtp import SmtpEdge, SmtpValidators

from gevent.event import Event
from gevent import monkey
monkey.patch_all()

class MyValidator(SmtpValidators):
    def __init__(self, session):
        self.session = session

    def handle_ehlo(self, reply, ehlo_as):
        reply.code = ''
        reply.message = "4.7.0 [IPTS04] Messages from x.x.x.x temporarily deferred due to user complaints - 4.16.55.1"

class MySmtpEdge(SmtpEdge):
    def __init__(self, listener, queue):
        super(MySmtpEdge, self).__init__(listener=listener, queue=queue, validator_class=MyValidator)

    def handoff(self, envelope):
        return [(envelope, "message")]

if __name__ == "__main__":
    edge = MySmtpEdge(('', 25), queue=None)
    edge.start()

    try:
        Event().wait()
    except:
        pass

The problem is this:
There is a BadReply error happening, that's why we get that message "Bad SMTP reply from server." and this is caught here but the BadReply's data attribute is lost in this method, basically it's exc.data that vanishes and I think it's not ok since the initial message sent from the SMTP server is valuable.

icgood added a commit that referenced this issue Feb 14, 2021
icgood added a commit that referenced this issue Feb 14, 2021
icgood added a commit that referenced this issue Feb 14, 2021
icgood added a commit that referenced this issue Feb 14, 2021
icgood added a commit that referenced this issue Feb 14, 2021
icgood added a commit that referenced this issue Feb 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants