-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Document MailAddress consecutive dots validation breaking change in .NET 10 #51023
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
docs/core/compatibility/networking/10.0/mailaddress-consecutive-dots.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| --- | ||
| title: "Breaking change - MailAddress enforces validation for consecutive dots" | ||
| description: "Learn about the breaking change in .NET 10 where MailAddress enforces stricter validation of email addresses with consecutive dots." | ||
gewarren marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ms.date: 01/12/2026 | ||
| ai-usage: ai-assisted | ||
| ms.custom: https://github.com/dotnet/docs/issues/51018 | ||
| --- | ||
|
|
||
| # MailAddress enforces validation for consecutive dots | ||
|
|
||
| Starting in .NET 10, the <xref:System.Net.Mail.MailAddress> class enforces stricter validation of email addresses. Email addresses with consecutive dots in the local part (for example, `[email protected]`) or domain part (for example, `[email protected]`) are now considered invalid. This change aligns the behavior of `MailAddress` with the email address format specified in [RFC 5322](https://www.rfc-editor.org/rfc/rfc5322.html) and [RFC 2822](https://www.rfc-editor.org/rfc/rfc2822.html). | ||
|
|
||
| ## Version introduced | ||
|
|
||
| .NET 10 Preview 1 | ||
|
|
||
| ## Previous behavior | ||
|
|
||
| Previously, the <xref:System.Net.Mail.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 executed without throwing an exception: | ||
|
|
||
| ```csharp | ||
| using System.Net.Mail; | ||
|
|
||
| var email = new MailAddress("[email protected]"); | ||
| Console.WriteLine(email.Address); // Output: [email protected] | ||
| ``` | ||
|
|
||
| ## New behavior | ||
|
|
||
| Starting in .NET 10, the <xref:System.Net.Mail.MailAddress> class enforces stricter validation and throws a <xref:System.FormatException> when it parses an email address with consecutive dots in the local or domain parts. | ||
|
|
||
| For example, the following code now throws a <xref:System.FormatException>: | ||
|
|
||
| ```csharp | ||
| using System.Net.Mail; | ||
|
|
||
| var email = new MailAddress("[email protected]"); // Throws FormatException | ||
| ``` | ||
|
|
||
| The exception message indicates that the email address is invalid. | ||
|
|
||
| ## Type of breaking change | ||
|
|
||
| This change is a [behavioral change](../../categories.md#behavioral-change). | ||
gewarren marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Reason for change | ||
|
|
||
| This change ensures compliance with the email address format specified in [RFC 5322](https://www.rfc-editor.org/rfc/rfc5322.html) and [RFC 2822](https://www.rfc-editor.org/rfc/rfc2822.html). 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 <xref:System.Net.Mail.MailAddress> for email validation. | ||
|
|
||
| ## Recommended action | ||
|
|
||
| If your application relies on the <xref:System.Net.Mail.MailAddress> class to parse email addresses, review your code to ensure that it doesn't pass email addresses with consecutive dots in the local or domain parts. If such addresses are encountered, update your application to handle the <xref:System.FormatException> that's now thrown. | ||
|
|
||
| For example, you can use a `try-catch` block to handle invalid email addresses: | ||
|
|
||
| ```csharp | ||
| 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 <xref:System.Net.Mail.MailAddress> constructor. | ||
|
|
||
| ## Affected APIs | ||
|
|
||
| - <xref:System.Net.Mail.MailAddress.%23ctor(System.String)> constructor | ||
| - <xref:System.Net.Mail.MailAddress.%23ctor(System.String,System.String)> constructor | ||
| - <xref:System.Net.Mail.MailAddress.%23ctor(System.String,System.String,System.Text.Encoding)> constructor | ||
|
|
||
| ## See also | ||
|
|
||
| - [Original pull request](https://github.com/dotnet/runtime/pull/109690) | ||
| - [Related issue](https://github.com/dotnet/runtime/issues/109590) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.