SmtpStatusCode 列舉

定義

指定使用 SmtpClient 類別傳送電子郵件的結果。

public enum class SmtpStatusCode
public enum SmtpStatusCode
type SmtpStatusCode = 
Public Enum SmtpStatusCode
繼承
SmtpStatusCode

欄位

BadCommandSequence 503

命令傳送順序不正確。

CannotVerifyUserWillAttemptDelivery 252

指定的使用者不是本機使用者,但是接收 SMTP 服務已接受訊息並嘗試傳遞訊息。 此狀態碼定義於 RFC 1123,可在 https://www.ietf.org 取得。

ClientNotPermitted 454

用戶端未通過驗證,或者不允許使用指定的 SMTP 主機傳送郵件。

CommandNotImplemented 502

SMTP 服務沒有實作指定的命令。

CommandParameterNotImplemented 504

SMTP 服務沒有實作指定的命令參數。

CommandUnrecognized 500

SMTP 服務無法辨識指定的命令。

ExceededStorageAllocation 552

訊息太大而無法儲存在目的信箱。

GeneralFailure -1

無法進行交易。 找不到指定的 SMTP 主機時,會收到這個錯誤。

HelpMessage 214

服務傳回的說明訊息。

InsufficientStorage 452

SMTP 服務沒有足夠儲存空間來完成要求。

LocalErrorInProcessing 451

SMTP 服務無法完成要求。 如果無法解析用戶端的 IP 位址,可能會發生此錯誤 (也就是反向對應失敗)。 如果用戶端網域已被識別為開放式轉送或來路不明的電子郵件 (垃圾郵件) 的來源,您也會收到此錯誤。 如需詳細資料,請參閱 RFC 2505,網址為 https://www.ietf.org

MailboxBusy 450

目的信箱正在使用中。

MailboxNameNotAllowed 553

用來指定目的信箱的語法不正確。

MailboxUnavailable 550

找不到目的信箱,或無法存取。

MustIssueStartTlsFirst 530

SMTP 伺服器設定為僅接受 TLS 連線,且 SMTP 用戶端正在嘗試使用非 TLS 連線連接。 該解決方法是讓使用者在 SMTP 用戶端上設定 EnableSsl=true。

Ok 250

電子郵件已成功傳送至 SMTP 服務。

ServiceClosingTransmissionChannel 221

SMTP 服務正在關閉傳送通道。

ServiceNotAvailable 421

SMTP 服務目前無法使用;伺服器正在關閉傳送通道。

ServiceReady 220

SMTP 服務已準備好。

StartMailInput 354

SMTP 服務已準備好接收電子郵件內容。

SyntaxError 501

用來指定命令或參數的語法不正確。

SystemStatus 211

系統狀態,或系統說明回覆。

TransactionFailed 554

交易失敗。

UserNotLocalTryAlternatePath 551

使用者信箱不在接收伺服器上。 您應該使用提供的地址資訊重新傳送。

UserNotLocalWillForward 251

使用者信箱不在接收伺服器上;伺服器將轉寄電子郵件。

範例

下列程式碼範例會在 擲回 時 SmtpException ,向主控台顯示錯誤訊息。

static void CreateMessageWithAttachment3( String^ server, String^ to )
{
   
   // Specify the file to be attached and sent.
   // This example assumes that a file named data.xls exists in the
   // current working directory.
   String^ file = L"data.xls";
   
   // Create a message and set up the recipients.
   MailMessage^ message = gcnew MailMessage( L"ReportMailer@contoso.com",to,L"Quarterly data report",L"See the attached spreadsheet." );
   
   // Create  the file attachment for this email message.
   Attachment^ data = gcnew Attachment("Qtr3.xls");
   
   
   // Add time stamp information for the file.
   ContentDisposition^ disposition = data->ContentDisposition;
   disposition->CreationDate = System::IO::File::GetCreationTime( file );
   disposition->ModificationDate = System::IO::File::GetLastWriteTime( file );
   disposition->ReadDate = System::IO::File::GetLastAccessTime( file );
   
   // Add the file attachment to this email message.
   message->Attachments->Add( data );
   
   //Send the message.
   SmtpClient^ client = gcnew SmtpClient( server );
   
   // Add credentials if the SMTP server requires them.
   client->Credentials = dynamic_cast<ICredentialsByHost^>(CredentialCache::DefaultNetworkCredentials);
   
   // Notify user if an error occurs.
   try
   {
      client->Send( message );
   }
   catch ( SmtpException^ e ) 
   {
      Console::WriteLine( L"Error: {0}", e->StatusCode );
   }
   finally
   {
      data->~Attachment();
      client->~SmtpClient();
   }

}
public static void CreateMessageWithAttachment3(string server, string to)
{
    // Specify the file to be attached and sent.
    // This example assumes that a file named Data.xls exists in the
    // current working directory.
    string file = "data.xls";
    // Create a message and set up the recipients.
    MailMessage message = new MailMessage(
       "ReportMailer@contoso.com",
       to,
       "Quarterly data report",
       "See the attached spreadsheet.");

    // Create  the file attachment for this email message.
    Attachment data = new Attachment("Qtr3.xls");
    // Add time stamp information for the file.
    ContentDisposition disposition = data.ContentDisposition;
    disposition.CreationDate = System.IO.File.GetCreationTime(file);
    disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
    disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
    // Add the file attachment to this email message.
    message.Attachments.Add(data);
    //Send the message.
    SmtpClient client = new SmtpClient(server);
    // Add credentials if the SMTP server requires them.
    client.Credentials = (ICredentialsByHost)CredentialCache.DefaultNetworkCredentials;
    // Notify user if an error occurs.
    try
    {
        client.Send(message);
    }
    catch (SmtpException e)
    {
        Console.WriteLine("Error: {0}", e.StatusCode);
    }
    finally
    {
        data.Dispose();
    }
}

備註

列舉中的值會指定 Simple Mail Transfer Protocol (SMTP) 伺服器所傳送的 SmtpStatusCode 回復狀態值。 SmtpExceptionSmtpFailedRecipientsException 類別包含 StatusCode 傳回 SmtpStatusCode 值的屬性。

SMTP 定義于 的 RFC https://www.ietf.org 2821 中。

適用於