SmtpException Constructors

Definition

Initializes a new instance of the SmtpException class.

Overloads

SmtpException()

Initializes a new instance of the SmtpException class.

SmtpException(SmtpStatusCode)

Initializes a new instance of the SmtpException class with the specified status code.

SmtpException(String)

Initializes a new instance of the SmtpException class with the specified error message.

SmtpException(SmtpStatusCode, String)

Initializes a new instance of the SmtpException class with the specified status code and error message.

SmtpException(SerializationInfo, StreamingContext)
Obsolete.

Initializes a new instance of the SmtpException class from the specified instances of the SerializationInfo and StreamingContext classes.

SmtpException(String, Exception)

Initializes a new instance of the SmtpException class with the specified error message and inner exception.

SmtpException()

Source:
SmtpException.cs
Source:
SmtpException.cs
Source:
SmtpException.cs

Initializes a new instance of the SmtpException class.

C#
public SmtpException();

Examples

The following code example demonstrates calling this constructor.

C#
public static SmtpException GenerateDefaultSmtpException()
{
    return new SmtpException();
}

Remarks

The exception returned by this constructor has its StatusCode property set to GeneralFailure.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

SmtpException(SmtpStatusCode)

Source:
SmtpException.cs
Source:
SmtpException.cs
Source:
SmtpException.cs

Initializes a new instance of the SmtpException class with the specified status code.

C#
public SmtpException(System.Net.Mail.SmtpStatusCode statusCode);

Parameters

statusCode
SmtpStatusCode

An SmtpStatusCode value.

Examples

The following code example demonstrates calling this constructor.

C#
public static SmtpException GenerateSmtpException(SmtpStatusCode status)
{
    return new SmtpException(status);
}

Remarks

This constructor uses the statusCode parameter to initialize the StatusCode property.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

SmtpException(String)

Source:
SmtpException.cs
Source:
SmtpException.cs
Source:
SmtpException.cs

Initializes a new instance of the SmtpException class with the specified error message.

C#
public SmtpException(string? message);
C#
public SmtpException(string message);

Parameters

message
String

A String that describes the error that occurred.

Examples

The following code example demonstrates calling this constructor.

C#
public static SmtpException GenerateSmtpException(string message)
{
    return new SmtpException(message);
}

Remarks

This constructor uses the message parameter to initialize the Message property.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

SmtpException(SmtpStatusCode, String)

Source:
SmtpException.cs
Source:
SmtpException.cs
Source:
SmtpException.cs

Initializes a new instance of the SmtpException class with the specified status code and error message.

C#
public SmtpException(System.Net.Mail.SmtpStatusCode statusCode, string? message);
C#
public SmtpException(System.Net.Mail.SmtpStatusCode statusCode, string message);

Parameters

statusCode
SmtpStatusCode

An SmtpStatusCode value.

message
String

A String that describes the error that occurred.

Examples

The following code example demonstrates calling this constructor.

C#
public static SmtpException GenerateSmtpException(SmtpStatusCode status, string message)
{
    return new SmtpException(status, message);
}

Remarks

This constructor uses the statusCode parameter to initialize the StatusCode property and uses the message parameter to initialize the Message property.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

SmtpException(SerializationInfo, StreamingContext)

Source:
SmtpException.cs
Source:
SmtpException.cs
Source:
SmtpException.cs

Caution

This API supports obsolete formatter-based serialization. It should not be called or extended by application code.

Initializes a new instance of the SmtpException class from the specified instances of the SerializationInfo and StreamingContext classes.

C#
[System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
protected SmtpException(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext);
C#
protected SmtpException(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext);

Parameters

serializationInfo
SerializationInfo

A SerializationInfo that contains the information required to serialize the new SmtpException.

streamingContext
StreamingContext

A StreamingContext that contains the source and destination of the serialized stream associated with the new instance.

Attributes

Remarks

This constructor implements the ISerializable interface for the SmtpException class.

Applies to

.NET 10 and other versions
Product Versions (Obsolete)
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7 (8, 9, 10)
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

SmtpException(String, Exception)

Source:
SmtpException.cs
Source:
SmtpException.cs
Source:
SmtpException.cs

Initializes a new instance of the SmtpException class with the specified error message and inner exception.

C#
public SmtpException(string? message, Exception? innerException);
C#
public SmtpException(string message, Exception innerException);

Parameters

message
String

A String that describes the error that occurred.

innerException
Exception

The exception that is the cause of the current exception.

Examples

The following code example demonstrates calling this constructor.

C#
public static SmtpException GenerateSmtpException(string message, Exception innerException)
{
    return new SmtpException(message, innerException);
}

Remarks

This constructor uses the message parameter to initialize the Message property and the innerException parameter to initialize the InnerException property.

If innerException is not null, the current exception is raised in a catch block that handles innerException.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1