diff --git a/xml/System.Net.Mail/SmtpClient.xml b/xml/System.Net.Mail/SmtpClient.xml index 11e440cfd6b..02b5d854808 100644 --- a/xml/System.Net.Mail/SmtpClient.xml +++ b/xml/System.Net.Mail/SmtpClient.xml @@ -58,51 +58,45 @@ - Allows applications to send email by using the Simple Mail Transfer Protocol (SMTP). The type is obsolete on some platforms and not recommended on others; for more information, see the Remarks section. + Sends email by using the Simple Mail Transfer Protocol (SMTP). The type is not recommended for new development; for more information, see the Remarks section. - [!IMPORTANT] -> We don't recommend that you use the `SmtpClient` class for new development because `SmtpClient` doesn't support many modern protocols. Use [MailKit](https://github.com/jstedfast/MailKit) or other libraries instead. For more information, see [SmtpClient shouldn't be used](https://github.com/dotnet/platform-compat/blob/master/docs/DE0005.md) on GitHub. +> We don't recommend that you use the `SmtpClient` class for new development because `SmtpClient` doesn't support many modern protocols. Use [MailKit](https://github.com/jstedfast/MailKit) or other libraries instead. For more information, see [SmtpClient shouldn't be used](https://github.com/dotnet/platform-compat/blob/master/docs/DE0005.md). -The `SmtpClient` class is obsolete in Xamarin. However: +The `SmtpClient` class is: -- It is included in the .NET Standard 2.0 and later versions and therefore must be part of any .NET implementation that supports those versions. -- It is present and can be used in .NET Framework 4 through .NET Framework 4.8. -- It is usable in .NET Core, but its use isn't recommended. +- Included in .NET Standard 2.0 and later versions and therefore must be part of any .NET implementation that supports those versions. +- Present and can be used in .NET Framework 4 through .NET Framework 4.8. +- Usable in .NET (Core), but its use isn't recommended. The classes shown in the following table are used to construct email messages that can be sent using . -|Class|Description| -|-----------|-----------------| -||Represents file attachments. This class allows you to attach files, streams, or text to an email message.| -||Represents the email address of the sender and recipients.| -||Represents an email message.| +| Class | Description | +|------------------------------------|------------------------------------------------------------| +| | Represents file attachments. This class allows you to attach files, streams, or text to an email message. | +| | Represents the email address of the sender and recipients. | +| | Represents an email message. | To construct and send an email message by using , you must specify the following information: -- The SMTP host server that you use to send email. See the and properties. - -- Credentials for authentication, if required by the SMTP server. See the property. - -- The email address of the sender. See the and methods that take a `from` parameter. Also see the property. - -- The email address or addresses of the recipients. See the and methods that take a `recipient` parameter. Also see the property. - -- The message content. See the and methods that take a `body` parameter. Also see the property. - - To include an attachment with an email message, first create the attachment by using the class, and then add it to the message by using the property. Depending on the email reader used by the recipients and the file type of the attachment, some recipients might not be able to read the attachment. For clients that cannot display the attachment in its original form, you can specify alternate views by using the property. +- The SMTP host server that you use to send email. See the and properties. +- Credentials for authentication, if required by the SMTP server. See the property. +- The email address of the sender. See the and methods that take a `from` parameter. Also see the property. +- The email address or addresses of the recipients. See the and methods that take a `recipient` parameter. Also see the property. +- The message content. See the and methods that take a `body` parameter. Also see the property. + +To include an attachment with an email message, first create the attachment by using the class, and then add it to the message by using the property. Depending on the email reader used by the recipients and the file type of the attachment, some recipients might not be able to read the attachment. For clients that cannot display the attachment in its original form, you can specify alternate views by using the property. In .NET Framework, you can use the application or machine configuration files to specify default host, port, and credentials values for all objects. For more information, see [<mailSettings> Element (Network Settings)](/dotnet/framework/configure-apps/file-schema/network/mailsettings-element-network-settings). .NET Core does not support setting defaults. As a workaround, you must set the relevant properties on directly. To send the email message and block while waiting for the email to be transmitted to the SMTP server, use one of the synchronous methods. To allow your program's main thread to continue executing while the email is transmitted, use one of the asynchronous methods. The event is raised when a operation completes. To receive this event, you must add a delegate to . The delegate must reference a callback method that handles notification of events. To cancel an asynchronous email transmission, use the method. > [!NOTE] -> If there is an email transmission in progress and you call or again, you will receive an . +> If there is an email transmission in progress and you call or again, you will receive an . The connection established by the current instance of the class to the SMTP server may be re-used if an application wishes to send multiple messages to the same SMTP server. This is particularly useful when authentication or encryption are used establish a connection to the SMTP server. The process of authenticating and establishing a TLS session can be expensive operations. A requirement to re-establish a connection for each message when sending a large quantity of email to the same SMTP server could have a significant impact on performance. There are a number of high-volume email applications that send email status updates, newsletter distributions, or email alerts. Also many email client applications support an off-line mode where users can compose many email messages that are sent later when a connection to the SMTP server is established. It is typical for an email client to send all SMTP messages to a specific SMTP server (provided by the Internet service provider) that then forwards this email to other SMTP servers. @@ -112,12 +106,11 @@ The classes shown in the following table are used to construct email messages th The class has no `Finalize` method, so an application must call to explicitly free up resources. The method iterates through all established connections to the SMTP server specified in the property and sends a QUIT message followed by gracefully ending the TCP connection. The method also releases the unmanaged resources used by the and optionally disposes of the managed resources. - Call when you are finished using the . The method leaves the in an unusable state. After calling , you must release all references to the so the garbage collector can reclaim the memory that the was occupying. - - - + Call when you are finished using the . The method leaves the in an unusable state. After calling , you must release all references to the so the garbage collector can reclaim the memory that the was occupying. + ## Examples - The following code example demonstrates sending an email message asynchronously. + +The following code example demonstrates sending an email message asynchronously. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_Remoting/NclMailASync/cpp/mailasync.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System.Net.Mail/MailAddress/.ctor/mailasync.cs" id="Snippet1":::