jstedfast / MailKit

A cross-platform .NET library for IMAP, POP3, and SMTP.
http://www.mimekit.net
MIT License
6.04k stars 809 forks source link

SmtpProtocolException - Last Smtp Response before failure #1744

Closed tinohager closed 2 months ago

tinohager commented 2 months ago

Describe the solution you'd like

I try to send a mail but the ip is blocked by Spamhaus, in my case it is a dynamic ip from my private internet access. It would be important for me to receive the smtp response I got. Which then triggers the SmtpProtocolException is this possible?

The exception.Message not contains 550 5.7.1 Service unavailable, Client host [123.123.123.123] blocked using Spamhaus. it contains The SMTP server has unexpectedly disconnected. https://github.com/jstedfast/MailKit/blob/0bb9c61344f7af9d57cc732301f6d4e088c6ff3d/MailKit/Net/Smtp/SmtpStream.cs#L275

C: MAIL FROM:<sender@domain.com> SIZE=1618
C: RCPT TO:<recipient@domain.net>
S: 550 5.7.1 Service unavailable, Client host [123.123.123.123] blocked using Spamhaus.
jstedfast commented 2 months ago

Yes, if you disable the PIPELINE extension, you'll get that response in the exception message.

client.Capabilities &= ~SmtpCapabilities.Pipelining;

Add that code before sending the message.

jstedfast commented 2 months ago

I just released MailKit v4.5.0 with the fix for this.

tinohager commented 2 months ago

many thanks for the customization

tinohager commented 2 months ago

Yes, if you disable the PIPELINE extension, you'll get that response in the exception message.

client.Capabilities &= ~SmtpCapabilities.Pipelining;

Add that code before sending the message.

Unfortunately, this solution does not work, the SmtpProtocolException is still triggered

tinohager commented 2 months ago

I just released MailKit v4.5.0 with the fix for this.

I would like to see the last smtp error message available as a field. Instead of mixing a text block from the library with the smtp error code. If someone wants to search for the error they will find nothing in the requested part. I could of course build a logic that removes the first part but I would find that unattractive. 😞

jstedfast commented 2 months ago

Unfortunately, this solution does not work, the SmtpProtocolException is still triggered

I know, but it would get you the response message.