MailMessage.Dispose Method ()


Releases all resources used by the MailMessage.

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

public void Dispose()

Call the Dispose method when you are finished using the MailMessage. The Dispose method leaves the MailMessage in an unusable state. After calling Dispose, you must release all references to the MailMessage so the garbage collector can reclaim the memory that the MailMessage was occupying. For more information, see Cleaning Up Unmanaged Resources and Implementing a Dispose Method.


Always call Dispose before you release your last reference to the MailMessage.

Legacy Code Example

The following code example demonstrates disposing a MailMessage.

.NET Framework
Available since 2.0
Return to top
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft