jstedfast / MailKit

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

Sending mail via SMTP aborts if a user is unknown #256

Closed RoyTinker closed 8 years ago

RoyTinker commented 8 years ago

It would be really great if there was an option to specifically ignore 550 [...] User unknown.

Thanks for this great utility!

jstedfast commented 8 years ago

I'm honestly having trouble understanding the use-case for this. Normally, if an address doesn't exist, you need to abort sending the message and notify the user that one of the addresses does not exist and allow the user to fix it/remove it and then send again.

Allowing the message to go through is just awkward unless you are writing a mass mailer that doesn't care if addresses are invalid/unavailable.

I'm also not really keen on adding awkward bool properties to SmtpClient to specify corner-case behaviors.

RoyTinker commented 8 years ago

I'm using MimeKit/MailKit to send automated notification emails internally from an intranet application. From time to time, I receive a "Hey! So and so did not get notified of XYZ" email, and it's always been due to a problem outside of my control: either an alias isn't configured correctly, or someone who doesn't work here anymore was accidentally added to a form, etc.

Manually checking each mail address against the internal LDAP database could solve some of the problem, but there are issues that would only show up in the SMTP session with a 550 error, like aliases that aren't configured correctly. (And there are valid addresses that the LDAP database does not know about.)

In my opinion, the best solution would be for the app to send the message anyway and notify the responsible devs of the problem.

The application in question facilitates a pretty high-profile process; so if problem notification emails aren't sent and have to wait for a dev to fix, I'll have frustrated users.

RoyTinker commented 8 years ago

I'd be happy if you only marked SmtpClient#ProcessMailFromResponse and SmtpClient#ProcessRcptToResponse protected so I could provide different behavior in a subclass. I'll submit a PR for that if you like.

jstedfast commented 8 years ago

if MAIL FROM fails, there's no way to recover, so I left that one private for now.

RoyTinker commented 8 years ago

Thanks Jeffrey, much appreciated.

RoyTinker commented 8 years ago

Hey, also, before I go --- thanks so much for the quick turnaround and the really great libraries.

jstedfast commented 8 years ago

Hey @TimTheTinker, another user in issue #309 has a similar problem and the current ProcessRcptToCommand() method does not provide enough context for their use case.

I am proposing to modify that method to also take the MimeMessage object that is currently being sent as a possible solution and both wanted to keep you updated on the potential API breakage but also to solicit feedback from you to see if that would be useful to you (perhaps you might run into the same situation he brought up (which is "what to do if all recipients are rejected?").