Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 12, 2026

Starting in .NET 10 Preview 1, System.Net.Mail.MailAddress rejects email addresses with consecutive dots (e.g., [email protected]) per RFC 5322/2822 compliance. Previously allowed, these now throw FormatException.

Changes

  • Added breaking change article (docs/core/compatibility/networking/10.0/mailaddress-consecutive-dots.md)

    • Documents behavioral change with before/after code examples
    • Explains RFC compliance rationale
    • Provides mitigation guidance (try-catch, pre-validation)
    • Lists affected constructor overloads
  • Updated index and TOC

    • Added entry to docs/core/compatibility/10.md under Networking section
    • Added entry to docs/core/compatibility/toc.yml for navigation

Example Impact

// Previously: no exception
var email = new MailAddress("[email protected]");

// .NET 10+: throws FormatException
try {
    var email = new MailAddress("[email protected]");
} catch (FormatException ex) {
    // Handle invalid address
}

Related: dotnet/runtime#109590, dotnet/runtime#109690

Original prompt

This section details on the original issue you should resolve

<issue_title>[Breaking change]: MailAddress accepts invalid email address with consecutive dots</issue_title>
<issue_description>## [Breaking change]: MailAddress now enforces validation for email addresses with consecutive dots

Description

Starting in .NET 10 Preview 1, the System.Net.Mail.MailAddress class has been updated to enforce stricter validation of email addresses. Specifically, email addresses with consecutive dots in the local part (e.g., [email protected]) or domain part (e.g., [email protected]) are now considered invalid. This change aligns the behavior of MailAddress with the email address format specified in RFC 5322 and RFC 2822.

This change was introduced to address dotnet/runtime#109590.

Version

.NET 10 Preview 1

Previous behavior

The MailAddress class allowed email addresses with consecutive dots in the local or domain parts, even though such addresses are invalid according to the email address specification.

For example, the following code would execute without throwing an exception:

using System.Net.Mail;

var email = new MailAddress("[email protected]");
Console.WriteLine(email.Address); // Output: [email protected]

New behavior

Starting in .NET 10 Preview 1, the MailAddress class enforces stricter validation and throws a FormatException when parsing email addresses with consecutive dots in the local or domain parts.

For example, the following code will now throw a FormatException:

using System.Net.Mail;

var email = new MailAddress("[email protected]"); // Throws FormatException

The exception message will indicate that the email address is invalid.

Type of breaking change

  • Behavioral change: Existing binaries might behave differently at runtime.

Reason for change

This change was introduced to ensure compliance with the email address format specified in RFC 5322 and RFC 2822. According to these standards, email addresses with consecutive dots in the local or domain parts are invalid. The previous behavior of allowing such addresses was incorrect and could lead to unexpected issues in applications relying on MailAddress for email validation.

Recommended action

If your application relies on the MailAddress class to parse email addresses, review your code to ensure that it does not pass email addresses with consecutive dots in the local or domain parts. If such addresses are encountered, you should update your application to handle the FormatException that will now be thrown.

For example, you can use a try-catch block to handle invalid email addresses:

using System;
using System.Net.Mail;

try
{
    var email = new MailAddress("[email protected]");
}
catch (FormatException ex)
{
    Console.WriteLine($"Invalid email address: {ex.Message}");
}

Alternatively, you can validate email addresses using a regular expression before passing them to the MailAddress constructor.

Feature area

  • Networking

Affected APIs

  • System.Net.Mail.MailAddress (all constructors)

For more information, see the original pull request and the related issue dotnet/runtime#109590.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.


Internal previews

📄 File 🔗 Preview link
docs/core/compatibility/10.md Breaking changes in .NET 10
docs/core/compatibility/networking/10.0/mailaddress-consecutive-dots.md MailAddress enforces validation for consecutive dots
docs/core/compatibility/toc.yml docs/core/compatibility/toc

Copilot AI changed the title [WIP] Fix MailAddress to enforce validation on consecutive dots Document MailAddress consecutive dots validation breaking change in .NET 10 Jan 12, 2026
Copilot AI requested a review from gewarren January 12, 2026 16:35
@gewarren gewarren marked this pull request as ready for review January 13, 2026 18:33
@gewarren gewarren requested a review from a team as a code owner January 13, 2026 18:33
Copilot AI review requested due to automatic review settings January 13, 2026 18:33
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR documents a breaking change in .NET 10 where System.Net.Mail.MailAddress now enforces RFC-compliant validation by rejecting email addresses with consecutive dots (e.g., [email protected]).

Changes:

  • Added breaking change documentation article explaining the new validation behavior
  • Updated the compatibility index and TOC to include the new entry in the Networking section

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
docs/core/compatibility/networking/10.0/mailaddress-consecutive-dots.md New breaking change documentation explaining the consecutive dots validation enforcement
docs/core/compatibility/10.md Added entry to the Networking section table linking to the new breaking change article
docs/core/compatibility/toc.yml Added navigation entry for the new breaking change document

@gewarren gewarren merged commit 99de702 into main Jan 14, 2026
17 checks passed
@gewarren gewarren deleted the copilot/fix-mailaddress-validation branch January 14, 2026 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Breaking change]: MailAddress accepts invalid email address with consecutive dots

3 participants