SmtpMail Class

Note: This API is now obsolete.

Provides properties and methods for sending messages using the Collaboration Data Objects for Windows 2000 (CDOSYS) message component. Recommended alternative: System.Net.Mail.

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


[ObsoleteAttribute("The recommended alternative is System.Net.Mail.SmtpClient.")]
public class SmtpMail


Gets or sets the name of the SMTP relay mail server to use to send e-mail messages. Recommended alternative: System.Net.Mail.


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.)


Gets the Type of the current instance.(Inherited from Object.)


Creates a shallow copy of the current Object.(Inherited from Object.)


Sends an e-mail message using arguments supplied in the properties of the MailMessage class. Recommended alternative: System.Net.Mail.

System_CAPS_pubmethodSystem_CAPS_staticSend(String, String, String, String)

Sends an e-mail message using the specified destination parameters. Recommended alternative: System.Net.Mail.


Returns a string that represents the current object.(Inherited from Object.)

The mail message can be delivered either through the SMTP mail service built into Microsoft Windows 2000 or through an arbitrary SMTP server. Types in the System.Web.Mail namespace can be used from ASP.NET or from any managed application.

If the SmtpServer property is not set, mail is by default queued on a Windows 2000 system, ensuring that the calling program does not block network traffic. If the SmtpMail property is set, the mail is delivered directly to the specified server.

The following example can be compiled to a console application that is used to send email from a command line. If you compile the example to a file named MailMessage.exe, use the executable file to send email as follows:

MailMessage test hello
using System;
using System.Web.Mail;

namespace SendMail
   class usage
      public void DisplayUsage()
         Console.WriteLine("Usage SendMail.exe <to> <from> <subject> <body>");
         Console.WriteLine("<to> the addresses of the email recipients");
         Console.WriteLine("<from> your email address");
         Console.WriteLine("<subject> subject of your email");
         Console.WriteLine("<body> the text of the email");
         Console.WriteLine("SendMail.exe; Hi hello");

   class Start
      // The main entry point for the application.
      static void Main(string[] args)
               MailMessage Message = new MailMessage();
               Message.To = args[0];
               Message.From = args[1];
               Message.Subject = args[2];
               Message.Body = args[3];

                  SmtpMail.SmtpServer = "your mail server name goes here";
               catch(System.Web.HttpException ehttp)
                  Console.WriteLine("{0}", ehttp.Message);
                  Console.WriteLine("Here is the full error message output");
                  Console.Write("{0}", ehttp.ToString());
               usage use = new usage();
         catch(System.Exception e)
            Console.WriteLine("Unknown Exception occurred {0}", e.Message);
            Console.WriteLine("Here is the Full Message output");
            Console.WriteLine("{0}", e.ToString());

.NET Framework
Available since 1.1

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

Return to top