Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/core/compatibility/10.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ If you're migrating an app to .NET 10, the breaking changes listed here might af
| Title | Type of change |
|-------|-------------------|
| [HTTP/3 support disabled by default with PublishTrimmed](networking/10.0/http3-disabled-with-publishtrimmed.md) | Source incompatible |
| [MailAddress enforces validation for consecutive dots](networking/10.0/mailaddress-consecutive-dots.md) | Behavioral change |
| [Streaming HTTP responses enabled by default in browser HTTP clients](networking/10.0/default-http-streaming.md) | Behavioral change |
| [`Uri` length limits removed](networking/10.0/uri-length-limits-removed.md) | Behavioral change |

Expand Down
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."
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).

## 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)
2 changes: 2 additions & 0 deletions docs/core/compatibility/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ items:
items:
- name: HTTP/3 support disabled by default with PublishTrimmed
href: networking/10.0/http3-disabled-with-publishtrimmed.md
- name: MailAddress enforces validation for consecutive dots
href: networking/10.0/mailaddress-consecutive-dots.md
- name: Streaming HTTP responses enabled by default in browser HTTP clients
href: networking/10.0/default-http-streaming.md
- name: "'Uri' length limits removed"
Expand Down