diff --git a/src/libraries/System.Net.Mail/Directory.Build.props b/src/libraries/System.Net.Mail/Directory.Build.props index 4784967b7f86a..5a1a0f181caaa 100644 --- a/src/libraries/System.Net.Mail/Directory.Build.props +++ b/src/libraries/System.Net.Mail/Directory.Build.props @@ -3,6 +3,5 @@ Open true - browser - \ No newline at end of file + diff --git a/src/libraries/System.Net.Mail/ref/System.Net.Mail.cs b/src/libraries/System.Net.Mail/ref/System.Net.Mail.cs index e59605eb60f29..5826634dd14a9 100644 --- a/src/libraries/System.Net.Mail/ref/System.Net.Mail.cs +++ b/src/libraries/System.Net.Mail/ref/System.Net.Mail.cs @@ -165,6 +165,7 @@ public enum MailPriority High = 2, } public delegate void SendCompletedEventHandler(object sender, System.ComponentModel.AsyncCompletedEventArgs e); + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public partial class SmtpClient : System.IDisposable { public SmtpClient() { } diff --git a/src/libraries/System.Net.Mail/src/Resources/Strings.resx b/src/libraries/System.Net.Mail/src/Resources/Strings.resx index b04e8c6d8d1e2..a72e327927cce 100644 --- a/src/libraries/System.Net.Mail/src/Resources/Strings.resx +++ b/src/libraries/System.Net.Mail/src/Resources/Strings.resx @@ -334,7 +334,4 @@ IIS delivery is not supported. - - System.Net.Mail is not supported on this platform. - diff --git a/src/libraries/System.Net.Mail/src/System.Net.Mail.csproj b/src/libraries/System.Net.Mail/src/System.Net.Mail.csproj index 0bc8b1c63c460..cad02d8a38a7f 100644 --- a/src/libraries/System.Net.Mail/src/System.Net.Mail.csproj +++ b/src/libraries/System.Net.Mail/src/System.Net.Mail.csproj @@ -5,10 +5,7 @@ enable - - SR.SystemNetMail_PlatformNotSupported - - + @@ -43,42 +40,22 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); + } + + public int Port + { + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); + } + + public bool UseDefaultCredentials + { + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); + } + + public ICredentialsByHost? Credentials + { + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); + } + + public int Timeout + { + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); + } + + public ServicePoint ServicePoint + { + get => throw new PlatformNotSupportedException(); + } + + public SmtpDeliveryMethod DeliveryMethod + { + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); + } + + public SmtpDeliveryFormat DeliveryFormat + { + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); + } + + public string? PickupDirectoryLocation + { + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); + } + + /// + /// Set to true if we need SSL + /// + public bool EnableSsl + { + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); + } + + /// + /// Certificates used by the client for establishing an SSL connection with the server. + /// + public X509CertificateCollection ClientCertificates => throw new PlatformNotSupportedException(); + + public string? TargetName + { + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); + } + + private bool ServerSupportsEai => throw new PlatformNotSupportedException(); + + public void Send(string from, string recipients, string? subject, string? body) => throw new PlatformNotSupportedException(); + + public void Send(MailMessage message) => throw new PlatformNotSupportedException(); + + public void SendAsync(string from, string recipients, string? subject, string? body, object? userToken) => throw new PlatformNotSupportedException(); + + public void SendAsync(MailMessage message, object? userToken) => throw new PlatformNotSupportedException(); + + public void SendAsyncCancel() => throw new PlatformNotSupportedException(); + + //************* Task-based async public methods ************************* + public Task SendMailAsync(string from, string recipients, string? subject, string? body) => throw new PlatformNotSupportedException(); + + public Task SendMailAsync(MailMessage message) => throw new PlatformNotSupportedException(); + + public Task SendMailAsync(string from, string recipients, string? subject, string? body, CancellationToken cancellationToken) => throw new PlatformNotSupportedException(); + + public Task SendMailAsync(MailMessage message, CancellationToken cancellationToken) => throw new PlatformNotSupportedException(); + + protected void OnSendCompleted(AsyncCompletedEventArgs e) => throw new PlatformNotSupportedException(); + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { } + } +} diff --git a/src/libraries/System.Net.Mail/src/System/Net/Mail/SmtpClient.cs b/src/libraries/System.Net.Mail/src/System/Net/Mail/SmtpClient.cs index 9e87770828eba..cceff5d15fa1e 100644 --- a/src/libraries/System.Net.Mail/src/System/Net/Mail/SmtpClient.cs +++ b/src/libraries/System.Net.Mail/src/System/Net/Mail/SmtpClient.cs @@ -6,6 +6,7 @@ using System.Globalization; using System.IO; using System.Net.NetworkInformation; +using System.Runtime.Versioning; using System.Security; using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; @@ -31,6 +32,7 @@ public enum SmtpDeliveryFormat International = 1, // SMTPUTF8 - Email Address Internationalization (EAI) } + [UnsupportedOSPlatform("browser")] public class SmtpClient : IDisposable { private string? _host; diff --git a/src/libraries/System.Net.Mail/src/System/Net/Mail/SmtpFailedRecipientException.cs b/src/libraries/System.Net.Mail/src/System/Net/Mail/SmtpFailedRecipientException.cs index 6919990791abf..f3a5d300f0cc9 100644 --- a/src/libraries/System.Net.Mail/src/System/Net/Mail/SmtpFailedRecipientException.cs +++ b/src/libraries/System.Net.Mail/src/System/Net/Mail/SmtpFailedRecipientException.cs @@ -12,7 +12,10 @@ namespace System.Net.Mail public class SmtpFailedRecipientException : SmtpException, ISerializable { private readonly string? _failedRecipient; + +#pragma warning disable CS0649 // Browser - never assigned to internal bool fatal; +#pragma warning restore CS0649 public SmtpFailedRecipientException() : base() { } diff --git a/src/libraries/System.Net.Mail/tests/Functional/AssemblyInfo.cs b/src/libraries/System.Net.Mail/tests/Functional/AssemblyInfo.cs index 4f5a0ace5deef..54c8a4d926e5c 100644 --- a/src/libraries/System.Net.Mail/tests/Functional/AssemblyInfo.cs +++ b/src/libraries/System.Net.Mail/tests/Functional/AssemblyInfo.cs @@ -4,4 +4,3 @@ using Xunit; [assembly: ActiveIssue("https://github.com/dotnet/runtime/issues/34690", TestPlatforms.Windows, TargetFrameworkMonikers.Netcoreapp, TestRuntimes.Mono)] -[assembly: SkipOnMono("System.Net.Mail is not supported on wasm", TestPlatforms.Browser)] diff --git a/src/libraries/System.Net.Mail/tests/Functional/LoggingTest.cs b/src/libraries/System.Net.Mail/tests/Functional/LoggingTest.cs index 65c9d1c10abe0..34f29d5b65032 100644 --- a/src/libraries/System.Net.Mail/tests/Functional/LoggingTest.cs +++ b/src/libraries/System.Net.Mail/tests/Functional/LoggingTest.cs @@ -9,6 +9,7 @@ namespace System.Net.Mail.Tests { + [PlatformSpecific(~TestPlatforms.Browser)] // SmtpClient is not supported on Browser public class LoggingTest { [Fact] diff --git a/src/libraries/System.Net.Mail/tests/Functional/MailMessageTest.cs b/src/libraries/System.Net.Mail/tests/Functional/MailMessageTest.cs index 8b6382bb64ef3..1d7f0e236ef4e 100644 --- a/src/libraries/System.Net.Mail/tests/Functional/MailMessageTest.cs +++ b/src/libraries/System.Net.Mail/tests/Functional/MailMessageTest.cs @@ -146,6 +146,7 @@ public void SubjectAndEncodingTest() } [Fact] + [PlatformSpecific(~TestPlatforms.Browser)] // Not passing as internal System.Net.Mail.MailWriter stripped from build public void SentSpecialLengthMailAttachment_Base64Decode_Success() { // The special length follows pattern: (3N - 1) * 0x4400 + 1 diff --git a/src/libraries/System.Net.Mail/tests/Functional/SmtpClientCredentialsTest.cs b/src/libraries/System.Net.Mail/tests/Functional/SmtpClientCredentialsTest.cs index 824717a0d9c78..64d884412b8fd 100644 --- a/src/libraries/System.Net.Mail/tests/Functional/SmtpClientCredentialsTest.cs +++ b/src/libraries/System.Net.Mail/tests/Functional/SmtpClientCredentialsTest.cs @@ -11,10 +11,11 @@ namespace System.Net.Mail.Functional.Tests { + [PlatformSpecific(~TestPlatforms.Browser)] // SmtpClient is not supported on Browser public class SmtpClientCredentialsTest { private readonly string UserName = "user"; - private readonly string Password = Guid.NewGuid().ToString(); + private readonly string Password = Guid.NewGuid().ToString(); [Fact] public void Credentials_Unset_Null() diff --git a/src/libraries/System.Net.Mail/tests/Functional/SmtpClientTest.cs b/src/libraries/System.Net.Mail/tests/Functional/SmtpClientTest.cs index 3d55574f0cab3..9519ff7529f41 100644 --- a/src/libraries/System.Net.Mail/tests/Functional/SmtpClientTest.cs +++ b/src/libraries/System.Net.Mail/tests/Functional/SmtpClientTest.cs @@ -19,6 +19,7 @@ namespace System.Net.Mail.Tests { + [PlatformSpecific(~TestPlatforms.Browser)] // SmtpClient is not supported on Browser public class SmtpClientTest : FileCleanupTestBase { private SmtpClient _smtp; diff --git a/src/libraries/System.Net.Mail/tests/Functional/System.Net.Mail.Functional.Tests.csproj b/src/libraries/System.Net.Mail/tests/Functional/System.Net.Mail.Functional.Tests.csproj index 83bb83a34f4d2..7519783c1cbaf 100644 --- a/src/libraries/System.Net.Mail/tests/Functional/System.Net.Mail.Functional.Tests.csproj +++ b/src/libraries/System.Net.Mail/tests/Functional/System.Net.Mail.Functional.Tests.csproj @@ -2,8 +2,6 @@ true $(NetCoreAppCurrent) - - true @@ -31,4 +29,4 @@ - \ No newline at end of file + diff --git a/src/libraries/System.Net.Mail/tests/Unit/AssemblyInfo.cs b/src/libraries/System.Net.Mail/tests/Unit/AssemblyInfo.cs deleted file mode 100644 index 2991b965dfe9d..0000000000000 --- a/src/libraries/System.Net.Mail/tests/Unit/AssemblyInfo.cs +++ /dev/null @@ -1,6 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using Xunit; - -[assembly: SkipOnMono("System.Net.Mail is not supported on wasm", TestPlatforms.Browser)] diff --git a/src/libraries/System.Net.Mail/tests/Unit/SmtpConnectionTests/EhloParseExtensionsTest.cs b/src/libraries/System.Net.Mail/tests/Unit/SmtpConnectionTests/EhloParseExtensionsTest.cs index fa4333b952e4d..f0c3f437c180d 100644 --- a/src/libraries/System.Net.Mail/tests/Unit/SmtpConnectionTests/EhloParseExtensionsTest.cs +++ b/src/libraries/System.Net.Mail/tests/Unit/SmtpConnectionTests/EhloParseExtensionsTest.cs @@ -5,6 +5,7 @@ namespace System.Net.Mail.Tests { + [PlatformSpecific(~TestPlatforms.Browser)] // SmtpClient is not supported on Browser public class EhloParseExtensionsTest { private SmtpConnection _smtpConnection; diff --git a/src/libraries/System.Net.Mail/tests/Unit/System.Net.Mail.Unit.Tests.csproj b/src/libraries/System.Net.Mail/tests/Unit/System.Net.Mail.Unit.Tests.csproj index 79709820e29b9..06a2e27ed6424 100644 --- a/src/libraries/System.Net.Mail/tests/Unit/System.Net.Mail.Unit.Tests.csproj +++ b/src/libraries/System.Net.Mail/tests/Unit/System.Net.Mail.Unit.Tests.csproj @@ -2,11 +2,10 @@ true ../../src/Resources/Strings.resx - $(NetCoreAppCurrent)-Windows_NT;$(NetCoreAppCurrent)-Unix + $(NetCoreAppCurrent)-Windows_NT;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser annotations - @@ -19,7 +18,7 @@ - + @@ -36,16 +35,8 @@ Link="ProductionCode\MailAddress.cs" /> - - - - - - - - + + + + + + + + + + + +