SmtpStatusCode 枚举

定义

指定使用 SmtpClient 类发送电子邮件的结果。

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

字段

名称 说明
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

事务失败。

示例

以下代码示例在引发时向控制台 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) 服务器发送的回复状态值。 和SmtpExceptionSmtpFailedRecipientsException类包含StatusCode返回SmtpStatusCode值的属性。

SMTP 在 RFC 2821 中定义,可在 .https://www.ietf.org

适用于