Export (0) Print
Expand All

SmtpMail Class

NOTE: This class 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. http://go.microsoft.com/fwlink/?linkid=14202")] 
public class SmtpMail
/** @attribute ObsoleteAttribute("The recommended alternative is System.Net.Mail.SmtpClient. http://go.microsoft.com/fwlink/?linkid=14202") */ 
public class SmtpMail
ObsoleteAttribute("The recommended alternative is System.Net.Mail.SmtpClient. http://go.microsoft.com/fwlink/?linkid=14202") 
public class SmtpMail
Not applicable.

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 to@contoso.com from@contoso.com 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("Example:");
         Console.WriteLine("SendMail.exe SomeOne@Contoso.com;SomeOther@Contoso.com Me@contoso.com Hi hello");
      }
   }
 

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

               try
               {
                  SmtpMail.SmtpServer = "your mail server name goes here";
                  SmtpMail.Send(Message);
               }
               catch(System.Web.HttpException ehttp)
               {
                  Console.WriteLine("{0}", ehttp.Message);
                  Console.WriteLine("Here is the full error message output");
                  Console.Write("{0}", ehttp.ToString());
               }
            }
            catch(IndexOutOfRangeException)
            {
               usage use = new usage();
               use.DisplayUsage();
            }
         }
         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());
         }
      }
   }
}

import System.*;
import System.Web.Mail.*;
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("Example:");
        Console.WriteLine("SendMail.exe SomeOne@Contoso.com;" 
            + "SomeOther@Contoso.com Me@contoso.com Hi hello");
    } //DisplayUsage
} //Usage

class Start
{
    // The main entry point for the application.
    /** @attribute STAThread()
     */
    public static void main(String[] args)
    {
        try {
            try {
                MailMessage message = new MailMessage();
                message.set_To(args[0]);
                message.set_From(args[1]);
                message.set_Subject(args[2]);
                message.set_Body(args[3]);

                try {
                    SmtpMail.set_SmtpServer("your mail server name goes here");
                    SmtpMail.Send(message);
                }
                catch (System.Web.HttpException eHttp) {
                    Console.WriteLine("{0}", eHttp.get_Message());
                    Console.WriteLine("Here is the full error message output");
                    Console.Write("{0}", eHttp.ToString());
                }
            }
            catch (IndexOutOfRangeException exp) {
                Usage use = new Usage();
                use.DisplayUsage();
            }
        }
        catch (System.Exception e) {
            Console.WriteLine("Unknown Exception occurred {0}", e.get_Message());
            Console.WriteLine("Here is the Full Message output");
            Console.WriteLine("{0}", e.ToString());
        }
    } //main
} //Start()

System.Object
  System.Web.Mail.SmtpMail

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 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: 1.0, 1.1, 2.0
Obsolete (compiler warning) in 3.0

Community Additions

ADD
Show:
© 2014 Microsoft