SmtpFailedRecipientsException 类

定义

当使用 SmtpClient 发送的电子邮件无法传递给所有收件人时引发的异常。

此 API 支持产品基础结构,不能在代码中直接使用。

public ref class SmtpFailedRecipientsException : System::Net::Mail::SmtpFailedRecipientException
public class SmtpFailedRecipientsException : System.Net.Mail.SmtpFailedRecipientException
[System.Serializable]
public class SmtpFailedRecipientsException : System.Net.Mail.SmtpFailedRecipientException
type SmtpFailedRecipientsException = class
    inherit SmtpFailedRecipientException
    interface ISerializable
[<System.Serializable>]
type SmtpFailedRecipientsException = class
    inherit SmtpFailedRecipientException
    interface ISerializable
Public Class SmtpFailedRecipientsException
Inherits SmtpFailedRecipientException
继承
属性
实现

示例

下面的代码示例重新发送由于邮箱繁忙或不可用而未送达的电子邮件。

static void RetryIfBusy( String^ server )
{
   MailAddress^ from = gcnew MailAddress( L"ben@contoso.com" );
   MailAddress^ to = gcnew MailAddress( L"jane@contoso.com" );
   MailMessage^ message = gcnew MailMessage( from,to );
   
   // message.Subject = "Using the SmtpClient class.";
   message->Subject = L"Using the SmtpClient class.";
   message->Body = L"Using this feature, you can send an email message from an application very easily.";
   
   // Add a carbon copy recipient.
   MailAddress^ copy = gcnew MailAddress( L"Notifications@contoso.com" );
   message->CC->Add( copy );
   SmtpClient^ client = gcnew SmtpClient( server );
   
   // Include credentials if the server requires them.
   client->Credentials = dynamic_cast<ICredentialsByHost^>(CredentialCache::DefaultNetworkCredentials);
   Console::WriteLine( L"Sending an email message to {0} using the SMTP host {1}.", to->Address, client->Host );
   try
   {
      client->Send( message );
   }
   catch ( SmtpFailedRecipientsException^ ex ) 
   {
      for ( int i = 0; i < ex->InnerExceptions->Length; i++ )
      {
         SmtpStatusCode status = ex->InnerExceptions[ i ]->StatusCode;
         if ( status == SmtpStatusCode::MailboxBusy || status == SmtpStatusCode::MailboxUnavailable )
         {
            Console::WriteLine( L"Delivery failed - retrying in 5 seconds." );
            System::Threading::Thread::Sleep( 5000 );
            client->Send( message );
         }
         else
         {
            Console::WriteLine( L"Failed to deliver message to {0}", ex->InnerExceptions[ i ] );
         }

      }
   }
   catch ( Exception^ ex )
   {
       Console::WriteLine(L"Exception caught in RetryIfBusy(): {0}", 
                     ex->ToString() );
   }
   finally
   {
      client->~SmtpClient();
   }
}
public static void RetryIfBusy(string server)
{
    MailAddress from = new MailAddress("ben@contoso.com");
    MailAddress to = new MailAddress("jane@contoso.com");
    MailMessage message = new MailMessage(from, to);
    // message.Subject = "Using the SmtpClient class.";
    message.Subject = "Using the SmtpClient class.";
    message.Body = @"Using this feature, you can send an email message from an application very easily.";
    // Add a carbon copy recipient.
    MailAddress copy = new MailAddress("Notifications@contoso.com");
    message.CC.Add(copy);
    SmtpClient client = new SmtpClient(server);
    // Include credentials if the server requires them.
    client.Credentials = (ICredentialsByHost)CredentialCache.DefaultNetworkCredentials;
    Console.WriteLine("Sending an email message to {0} using the SMTP host {1}.",
         to.Address, client.Host);
    try
    {
        client.Send(message);
    }
    catch (SmtpFailedRecipientsException ex)
    {
        for (int i = 0; i < ex.InnerExceptions.Length; i++)
        {
            SmtpStatusCode status = ex.InnerExceptions[i].StatusCode;
            if (status == SmtpStatusCode.MailboxBusy ||
                status == SmtpStatusCode.MailboxUnavailable)
            {
                Console.WriteLine("Delivery failed - retrying in 5 seconds.");
                System.Threading.Thread.Sleep(5000);
                client.Send(message);
            }
            else
            {
                Console.WriteLine("Failed to deliver message to {0}",
                    ex.InnerExceptions[i].FailedRecipient);
            }
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine("Exception caught in RetryIfBusy(): {0}",
                ex.ToString() );
    }
}

注解

InnerExceptions 属性包含尝试发送电子邮件时收到的异常。 电子邮件可能已成功传递到某些收件人。

构造函数

SmtpFailedRecipientsException()

此 API 支持产品基础结构,不能在代码中直接使用。

初始化 SmtpFailedRecipientsException 类的空实例。

SmtpFailedRecipientsException(SerializationInfo, StreamingContext)

此 API 支持产品基础结构,不能在代码中直接使用。

SmtpFailedRecipientsExceptionSerializationInfo 类的指定实例初始化 StreamingContext 类的新实例。

SmtpFailedRecipientsException(String)

此 API 支持产品基础结构,不能在代码中直接使用。

使用指定的 SmtpFailedRecipientsException 初始化 String 类的新实例。

SmtpFailedRecipientsException(String, Exception)

此 API 支持产品基础结构,不能在代码中直接使用。

使用指定的 String 和内部 Exception 初始化 SmtpFailedRecipientsException 类的新实例。

SmtpFailedRecipientsException(String, SmtpFailedRecipientException[])

此 API 支持产品基础结构,不能在代码中直接使用。

使用指定的 String 和类型为 SmtpFailedRecipientException 的数组初始化 SmtpFailedRecipientsException 类的新实例。

属性

Data

获取键/值对的集合,这些键/值对提供有关该异常的其他用户定义信息。

(继承自 Exception)
FailedRecipient

指示有发送困难的电子邮件地址。

(继承自 SmtpFailedRecipientException)
HelpLink

获取或设置指向与此异常关联的帮助文件链接。

(继承自 Exception)
HResult

获取或设置 HRESULT(一个分配给特定异常的编码数字值)。

(继承自 Exception)
InnerException

获取导致当前异常的 Exception 实例。

(继承自 Exception)
InnerExceptions

此 API 支持产品基础结构,不能在代码中直接使用。

获取一个或多个 SmtpFailedRecipientException,指示存在 SMTP 传递错误的电子邮件收件人。

Message

获取描述当前异常的消息。

(继承自 Exception)
Source

获取或设置导致错误的应用程序或对象的名称。

(继承自 Exception)
StackTrace

获取调用堆栈上的即时框架字符串表示形式。

(继承自 Exception)
StatusCode

获取传输电子邮件时由 SMTP 服务器返回的状态代码。

(继承自 SmtpException)
TargetSite

获取引发当前异常的方法。

(继承自 Exception)

方法

Equals(Object)

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

(继承自 Object)
GetBaseException()

当在派生类中重写时,返回 Exception,它是一个或多个并发的异常的根本原因。

(继承自 Exception)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetObjectData(SerializationInfo, StreamingContext)

用序列化 SmtpFailedRecipientsException 所需的数据来填充 SerializationInfo 实例。

GetType()

获取当前实例的运行时类型。

(继承自 Exception)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

创建并返回当前异常的字符串表示形式。

(继承自 Exception)

事件

SerializeObjectState
已过时。

当异常被序列化用来创建包含有关该异常的徐列出数据的异常状态对象时会出现该问题。

(继承自 Exception)

显式接口实现

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

根据指定的 SerializationInfoStreamingContext 实例初始化 SmtpFailedRecipientsException 类的新实例。

适用于