SmtpStatusCode 列舉
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指定使用 SmtpClient 類別傳送電子郵件的結果。
public enum class SmtpStatusCode
public enum SmtpStatusCode
type SmtpStatusCode =
Public Enum SmtpStatusCode
- 繼承
欄位
| 名稱 | 值 | Description |
|---|---|---|
| GeneralFailure | -1 | 交易無法完成。 當找不到指定的 SMTP 主機時,就會收到這個錯誤。 |
| SystemStatus | 211 | 系統狀態或系統說明回覆。 |
| HelpMessage | 214 | 服務方回覆了幫助訊息。 |
| ServiceReady | 220 | SMTP 服務已準備好。 |
| ServiceClosingTransmissionChannel | 221 | SMTP 服務正在關閉傳輸通道。 |
| Ok | 250 | 郵件已成功發送至 SMTP 服務。 |
| UserNotLocalWillForward | 251 | 使用者信箱不位於接收伺服器上;伺服器會轉發郵件。 |
| CannotVerifyUserWillAttemptDelivery | 252 | 指定的使用者並非本地使用者,但接收的 SMTP 服務已接受該訊息並嘗試傳送。 此狀態碼定義於 RFC 1123,該資料可於 https://www.ietf.org取得。 |
| StartMailInput | 354 | SMTP 服務已準備好接收電子郵件內容。 |
| ServiceNotAvailable | 421 | SMTP 服務無法提供;伺服器正在關閉傳輸通道。 |
| MailboxBusy | 450 | 目的地信箱正在使用中。 |
| LocalErrorInProcessing | 451 | SMTP 服務無法完成該請求。 若無法解析用戶端的 IP 位址(即反向查詢失敗),就可能發生此錯誤。 如果客戶網域被認定為開放中繼或非請自來郵件(垃圾郵件)來源,你也可能收到此錯誤。 詳情請參閱 RFC 2505,該文件可於 https://www.ietf.org。 |
| InsufficientStorage | 452 | SMTP 服務的儲存空間不足以完成請求。 |
| ClientNotPermitted | 454 | 用戶端未被認證,或不被允許使用指定的 SMTP 主機發送郵件。 |
| CommandUnrecognized | 500 | SMTP 服務無法辨識指定的指令。 |
| SyntaxError | 501 | 用來指定指令或參數的語法是錯誤的。 |
| CommandNotImplemented | 502 | SMTP 服務並未實作指定的指令。 |
| BadCommandSequence | 503 | 指令發送順序錯誤。 |
| CommandParameterNotImplemented | 504 | SMTP 服務並未實作指定的指令參數。 |
| MustIssueStartTlsFirst | 530 | SMTP 伺服器設定為僅接受 TLS 連線,而 SMTP 用戶端嘗試使用非 TLS 連線來連線。 解決方案是使用者在 SMTP 用戶端設定 EnableSsl=true 。 |
| MailboxUnavailable | 550 | 目的地信箱找不到或無法存取。 |
| UserNotLocalTryAlternatePath | 551 | 使用者信箱不位於接收伺服器上。 你應該用提供的地址資訊重新寄出。 |
| ExceededStorageAllocation | 552 | 訊息太大,無法儲存在目的地信箱中。 |
| MailboxNameNotAllowed | 553 | 用來指定目的地信箱的語法是錯誤的。 |
| TransactionFailed | 554 | 交易失敗了。 |
範例
以下程式碼範例在拋出 a SmtpException 時會向主控台顯示錯誤訊息。
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();
}
}
備註
列舉中的 SmtpStatusCode 值指定由簡易郵件傳輸協定(SMTP)伺服器傳送的回覆狀態值。 SmtpException與SmtpFailedRecipientsException類別包含StatusCode回傳SmtpStatusCode值的屬性。
SMTP 定義於 RFC 2821,網址可參考 https://www.ietf.org。