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

Empty email is send if address is reserved by rfc 2606 #1459

Closed
tamerlan opened this issue Nov 10, 2022 · 2 comments
Closed

Empty email is send if address is reserved by rfc 2606 #1459

tamerlan opened this issue Nov 10, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@tamerlan
Copy link

tamerlan commented Nov 10, 2022

Describe the bug
We are using the copy of production DB with obfuscated data hence some emails are invalid to avoid real users get the test notifications. But it turned out that if obfuscated email doesn't match the 5.1.4 of RFC MailKit sends the empty email to the all valid recepients in the list.

Platform (please complete the following information):

  • OS: Windows
  • .NET Runtime: CoreCLR
  • .NET Framework: .Net 6
  • MailKit Version: 3.4.2

Exception
5.1.4 Recipient address reserved by RFC 2606
at MailKit.Net.Smtp.SmtpClient.Send(FormatOptions options, MimeMessage message, MailboxAddress sender, IList`1 recipients, CancellationToken cancellationToken, ITransferProgress progress)
at MailKit.Net.Smtp.SmtpClient.Send(FormatOptions options, MimeMessage message, CancellationToken cancellationToken, ITransferProgress progress)
at MailKit.MailTransport.Send(MimeMessage message, CancellationToken cancellationToken, ITransferProgress progress)
at Program.

$(String[] args) in Program.cs:line 30

To Reproduce
Steps to reproduce the behavior:

  1. Try to send email to list of recepients one which is invalid. E.g. [email protected]
  2. Get the exception "5.1.4 Recipient address reserved by RFC 2606. "
  3. Verify that all other valid recepients received and empty email.

Expected behavior
Valid users received the normal email instead of empty

Code Snippets
If applicable, add code snippets to help explain your problem.

var message = new MimeMessage();
message.From.Add(new MailboxAddress("<Name>", "<Email>"));
message.To.Add(new MailboxAddress("Mrs. Chanandler Bong", "[email protected]"));
message.To.Add(new MailboxAddress("<Valid User>", "<Valid Email>"));
message.Subject = "How you doin'?";
message.Body = new TextPart("plain")
{
    Text = @"Hey Chandler,

I just wanted to let you know that Monica and I were going to go play some paintball, you in?

-- Joey"
};

try
{
    using (var client = new SmtpClient())
    {
        client.Connect("smtp.office365.com", 587, false);
        client.Authenticate("<UserName>", "<Password>");

        client.Send(message);
        client.Disconnect(true);
    }
}
catch (Exception e)
{
    Console.WriteLine(e);
    throw;
}
@jstedfast jstedfast added invalid This doesn't seem right server-bug The bug appears to be in the server labels Nov 10, 2022
@jstedfast
Copy link
Owner

This is a server bug and not the fault of MailKit at all.

@jstedfast jstedfast added bug Something isn't working and removed invalid This doesn't seem right server-bug The bug appears to be in the server labels Nov 10, 2022
@jstedfast
Copy link
Owner

What I think you are experiencing is that when an SMTP server supports the PIPELINING extension, MailKit will pipeline the MAIL FROM, RCPT TO, and DATA commands.

When the message being sent has a mix of valid and invalid recipients, by the time MailKit realizes that there were invalid recipients, the only thing it can do to abort the send is to terminate the DATA command by sending .\r\n which has the unfortunate side-effect where SMTP servers will treat that as an empty message and send it to all of the valid recipients.

The problem, really, is that pipelining SMTP commands does not translate well to a Send/SendAsync paradigm where it is expected that the message was either sent to all recipients or not sent at all.

I'll revert the commit that added the DATA command to the list of commands that get pipelined. The idea was to improve SMTP performance by saving an extra TCP/IP packet round-trip, but this issue is impossible to fix if we pipeline the DATA command.

@jstedfast jstedfast reopened this Nov 10, 2022
jstedfast added a commit that referenced this issue Nov 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants