SmtpClient Class

Allows applications to send e-mail by using the Simple Mail Transfer Protocol (SMTP).

Namespace: System.Net.Mail
Assembly: System (in system.dll)

Public Class SmtpClient
Dim instance As SmtpClient

public class SmtpClient
public class SmtpClient
Not applicable.

The SmtpClient class is used to send e-mail to an SMTP server for delivery. The classes shown in the following table are used to construct e-mail messages that can be sent using SmtpClient.




Represents file attachments. This class allows you to attach files, streams, or text to an e-mail message.


Represents the e-mail address of the sender and recipients.


Represents an e-mail message.

To construct and send an e-mail message by using SmtpClient, you must specify the following information:

  • The SMTP host server that you use to send e-mail. See the Host and Portproperties.

  • Credentials for authentication, if required by the SMTP server. See the Credentials property.

  • The e-mail address of the sender. See the Send and SendAsync methods that take a from parameter. Also see the MailMessage.From property.

  • The e-mail address or addresses of the recipients. See the Send and SendAsync methods that take a recipient parameter. Also see the MailMessage.To property.

  • The message content. See the Send and SendAsync methods that take a body parameter. Also see the MailMessage.Body property.

To include an attachment with an e-mail message, first create the attachment by using the Attachment class, and then add it to the message by using the MailMessage.Attachments property. Depending on the e-mail 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 MailMessage.AlternateViews property.

You can use the application or machine configuration files to specify default host, port, and credentials values for all SmtpClient objects. For more information, see mailSettings Element (Network Settings).

To send the e-mail message and block while waiting for the e-mail to be transmitted to the SMTP server, use one of the synchronous Send methods. To allow your program's main thread to continue executing while the e-mail is transmitted, use one of the asynchronous SendAsync methods. The SendCompleted event is raised when a SendAsync operation completes. To receive this event, you must add a SendCompletedEventHandler delegate to SendCompleted. The SendCompletedEventHandler delegate must reference a callback method that handles notification of SendCompleted events. To cancel an asynchronous e-mail transmission, use the SendAsyncCancel method.


If there is an e-mail transmission in progress and you call SendAsync or Send again, you will receive an InvalidOperationException.

SMTP is defined in RFC 2821, which is available at

How to: Install and Configure SMTP Virtual Servers in IISConfiguring ASP .NET Web Applications
How to: Install and Configure SMTP Virtual Servers in IISConfiguring ASP .NET Web Applications

The following code example demonstrates sending an e-mail message asynchronously.

No code example is currently available or this language may not be supported.


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions