SmtpStatusCode SmtpStatusCode SmtpStatusCode SmtpStatusCode Enum

Definition

Specifies the outcome of sending email by using the SmtpClient class.

public enum class SmtpStatusCode
public enum SmtpStatusCode
type SmtpStatusCode = 
Public Enum SmtpStatusCode
Inheritance
SmtpStatusCodeSmtpStatusCodeSmtpStatusCodeSmtpStatusCode

Fields

BadCommandSequence BadCommandSequence BadCommandSequence BadCommandSequence 503

The commands were sent in the incorrect sequence.

CannotVerifyUserWillAttemptDelivery CannotVerifyUserWillAttemptDelivery CannotVerifyUserWillAttemptDelivery CannotVerifyUserWillAttemptDelivery 252

The specified user is not local, but the receiving SMTP service accepted the message and attempted to deliver it. This status code is defined in RFC 1123, which is available at https://www.ietf.org.

ClientNotPermitted ClientNotPermitted ClientNotPermitted ClientNotPermitted 454

The client was not authenticated or is not allowed to send mail using the specified SMTP host.

CommandNotImplemented CommandNotImplemented CommandNotImplemented CommandNotImplemented 502

The SMTP service does not implement the specified command.

CommandParameterNotImplemented CommandParameterNotImplemented CommandParameterNotImplemented CommandParameterNotImplemented 504

The SMTP service does not implement the specified command parameter.

CommandUnrecognized CommandUnrecognized CommandUnrecognized CommandUnrecognized 500

The SMTP service does not recognize the specified command.

ExceededStorageAllocation ExceededStorageAllocation ExceededStorageAllocation ExceededStorageAllocation 552

The message is too large to be stored in the destination mailbox.

GeneralFailure GeneralFailure GeneralFailure GeneralFailure -1

The transaction could not occur. You receive this error when the specified SMTP host cannot be found.

HelpMessage HelpMessage HelpMessage HelpMessage 214

A Help message was returned by the service.

InsufficientStorage InsufficientStorage InsufficientStorage InsufficientStorage 452

The SMTP service does not have sufficient storage to complete the request.

LocalErrorInProcessing LocalErrorInProcessing LocalErrorInProcessing LocalErrorInProcessing 451

The SMTP service cannot complete the request. This error can occur if the client's IP address cannot be resolved (that is, a reverse lookup failed). You can also receive this error if the client domain has been identified as an open relay or source for unsolicited email (spam). For details, see RFC 2505, which is available at https://www.ietf.org.

MailboxBusy MailboxBusy MailboxBusy MailboxBusy 450

The destination mailbox is in use.

MailboxNameNotAllowed MailboxNameNotAllowed MailboxNameNotAllowed MailboxNameNotAllowed 553

The syntax used to specify the destination mailbox is incorrect.

MailboxUnavailable MailboxUnavailable MailboxUnavailable MailboxUnavailable 550

The destination mailbox was not found or could not be accessed.

MustIssueStartTlsFirst MustIssueStartTlsFirst MustIssueStartTlsFirst MustIssueStartTlsFirst 530

The SMTP server is configured to accept only TLS connections, and the SMTP client is attempting to connect by using a non-TLS connection. The solution is for the user to set EnableSsl=true on the SMTP Client.

Ok Ok Ok Ok 250

The email was successfully sent to the SMTP service.

ServiceClosingTransmissionChannel ServiceClosingTransmissionChannel ServiceClosingTransmissionChannel ServiceClosingTransmissionChannel 221

The SMTP service is closing the transmission channel.

ServiceNotAvailable ServiceNotAvailable ServiceNotAvailable ServiceNotAvailable 421

The SMTP service is not available; the server is closing the transmission channel.

ServiceReady ServiceReady ServiceReady ServiceReady 220

The SMTP service is ready.

StartMailInput StartMailInput StartMailInput StartMailInput 354

The SMTP service is ready to receive the email content.

SyntaxError SyntaxError SyntaxError SyntaxError 501

The syntax used to specify a command or parameter is incorrect.

SystemStatus SystemStatus SystemStatus SystemStatus 211

A system status or system Help reply.

TransactionFailed TransactionFailed TransactionFailed TransactionFailed 554

The transaction failed.

UserNotLocalTryAlternatePath UserNotLocalTryAlternatePath UserNotLocalTryAlternatePath UserNotLocalTryAlternatePath 551

The user mailbox is not located on the receiving server. You should resend using the supplied address information.

UserNotLocalWillForward UserNotLocalWillForward UserNotLocalWillForward UserNotLocalWillForward 251

The user mailbox is not located on the receiving server; the server forwards the email.

Examples

The following code example displays an error message to the console when an SmtpException is thrown.

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();
	}
}

Remarks

The values in the SmtpStatusCode enumeration specify reply status values sent by a Simple Mail Transfer Protocol (SMTP) server. The SmtpException and SmtpFailedRecipientsException classes contain StatusCode properties that return SmtpStatusCode values.

SMTP is defined in RFC 2821 available at https://www.ietf.org.

Applies to