SmtpMail 类

定义

注意

The recommended alternative is System.Net.Mail.SmtpClient. http://go.microsoft.com/fwlink/?linkid=14202

提供用于使用 Windows 2000 的协作数据对象 (CDOSYS) 消息组件来发送消息的属性和方法。 建议使用的替代项:System.Net.Mail

public ref class SmtpMail
public class SmtpMail
[System.Obsolete("The recommended alternative is System.Net.Mail.SmtpClient. http://go.microsoft.com/fwlink/?linkid=14202")]
public class SmtpMail
type SmtpMail = class
[<System.Obsolete("The recommended alternative is System.Net.Mail.SmtpClient. http://go.microsoft.com/fwlink/?linkid=14202")>]
type SmtpMail = class
Public Class SmtpMail
继承
SmtpMail
属性

示例

以下示例可以编译为用于从命令行发送电子邮件的控制台应用程序。 如果将示例编译为名为 MailMessage.exe 的文件,请使用可执行文件发送电子邮件,如下所示:

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());
         }
      }
   }
}
Imports System.Web.Mail
 
Namespace SendMail
   Public Class usage
      Public Sub DisplayUsage()
         ' Display usage instructions in case of error.
         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")
     End Sub
   End Class

   Public Class Start
      '  The main entry point for the application.
      Public Shared Sub Main(ByVal args As String())
         Try
            Try
               Dim Message As System.Web.Mail.MailMessage = New System.Web.Mail.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 ehttp As System.Web.HttpException
                  Console.WriteLine("0", ehttp.Message)
                  Console.WriteLine("Here is the full error message")
                  Console.Write("0", ehttp.ToString())
               End Try
            Catch e As IndexOutOfRangeException
               ' Display usage instructions if error in arguments.
               Dim use As usage = New usage()
               use.DisplayUsage()
            End Try
         Catch e As System.Exception
            ' Display text of unknown error.
            Console.WriteLine("Unknown Exception occurred 0", e.Message)
            Console.WriteLine("Here is the Full Error Message")
            Console.WriteLine("0", e.ToString())
         End Try
      End Sub
   End Class
End Namespace

注解

邮件可以通过内置于 Windows 2000 Microsoft 的 SMTP 邮件服务或通过任意 SMTP 服务器传递。 命名空间中的 System.Web.Mail 类型可以从 ASP.NET 或任何托管应用程序使用。

SmtpServer如果未设置 属性,则邮件默认在 Windows 2000 系统上排队,确保调用程序不会阻止网络流量。 SmtpMail如果设置了 属性,则邮件将直接传递到指定的服务器。

属性

SmtpServer
已过时.

获取或设置要用于发送电子邮件的 SMTP 中继邮件服务器的名称。 建议使用的替代项:System.Net.Mail

方法

Equals(Object)
已过时.

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()
已过时.

作为默认哈希函数。

(继承自 Object)
GetType()
已过时.

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()
已过时.

创建当前 Object 的浅表副本。

(继承自 Object)
Send(MailMessage)
已过时.

使用在 MailMessage 类的属性中提供的参数发送电子邮件。 建议使用的替代项:System.Net.Mail

Send(String, String, String, String)
已过时.

使用指定的目标参数发送电子邮件。 建议使用的替代项:System.Net.Mail

ToString()
已过时.

返回表示当前对象的字符串。

(继承自 Object)

适用于