Allows applications to send e-mail by using the Simple Mail Transfer Protocol (SMTP).
Assembly: System (in System.dll)
Initializes a new instance of theclass by using configuration file settings.
Initializes a new instance of theclass that sends e-mail by using the specified SMTP server.
Initializes a new instance of theclass that sends e-mail by using the specified SMTP server and port.
Specify which certificates should be used to establish the Secure Sockets Layer (SSL) connection.
Gets or sets the credentials used to authenticate the sender.
Gets or sets the delivery format used byto send e-mail.
Specifies how outgoing email messages will be handled.
Specify whether theuses Secure Sockets Layer (SSL) to encrypt the connection.
Gets or sets the name or IP address of the host used for SMTP transactions.
Gets or sets the folder where applications save mail messages to be processed by the local SMTP server.
Gets or sets the port used for SMTP transactions.
Gets the network connection used to transmit the e-mail message.
Gets or sets the Service Provider Name (SPN) to use for authentication when using extended protection.
Gets or sets a value that specifies the amount of time after which a synchronous Send call times out.
Sends a QUIT message to the SMTP server, gracefully ends the TCP connection, and releases all resources used by the current instance of theclass.
Sends a QUIT message to the SMTP server, gracefully ends the TCP connection, releases all resources used by the current instance of theclass, and optionally disposes of the managed resources.
Determines whether the specified object is equal to the current object.(Inherited from Object.)
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)
Serves as the default hash function. (Inherited from Object.)
Raises the SendCompleted event.
Sends the specified message to an SMTP server for delivery.
|Send(String, String, String, String)|
Sends the specified e-mail message to an SMTP server for delivery. The message sender, recipients, subject, and message body are specified using String objects.
Sends the specified e-mail message to an SMTP server for delivery. This method does not block the calling thread and allows the caller to pass an object to the method that is invoked when the operation completes.
|SendAsync(String, String, String, String, Object)|
Sends an e-mail message to an SMTP server for delivery. The message sender, recipients, subject, and message body are specified using String objects. This method does not block the calling thread and allows the caller to pass an object to the method that is invoked when the operation completes.
Cancels an asynchronous operation to send an e-mail message.
Sends the specified message to an SMTP server for delivery as an asynchronous operation.
|SendMailAsync(String, String, String, String)|
Sends the specified message to an SMTP server for delivery as an asynchronous operation. . The message sender, recipients, subject, and message body are specified using String objects.
Returns a string that represents the current object.(Inherited from Object.)
The http://www.ietf.org.class is used to send e-mail to an SMTP server for delivery. The SMTP protocol is defined in RFC 2821, which is available at
The classes shown in the following table are used to construct e-mail messages that can be sent using.
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, you must specify the following information:
Credentials for authentication, if required by the SMTP server. See the Credentials 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 <mailSettings> Element (Network Settings).objects. For more information, see
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.
The connection established by the current instance of theclass 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.
Theclass implementation pools SMTP connections so that it can avoid the overhead of re-establishing a connection for every message to the same server. An application may re-use the same object to send many different emails to the same SMTP server and to many different SMTP servers. As a result, there is no way to determine when an application is finished using the object and it should be cleaned up.
When an SMTP session is finished and the client wishes to terminate the connection, it must send a QUIT message to the server to indicate that it has no more messages to send. This allows the server to free up resources associated with the connection from the client and process the messages which were sent by the client.
The Dispose to explicitly free up resources. The Dispose method iterates through all established connections to the SMTP server specified in the Host property and sends a QUIT message followed by gracefully ending the TCP connection. The Dispose method also releases the unmanaged resources used by the Socket and optionally disposes of the managed resources.class has no Finalize method, so an application must call
Call Dispose when you are finished using the . The Dispose method leaves the in an unusable state. After calling Dispose, you must release all references to the so the garbage collector can reclaim the memory that the was occupying.
Available since 2.0
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.