Interface ITextProtocolTransport
Abstracts a line-oriented text protocol wire (TCP + optional TLS).
All socket I/O in SmtpClient,
Pop3Client, and ImapClient goes through this
interface so that unit tests can inject an in-process transport
without a real socket.
Inherited Members
Namespace: DRIT.Mail.Rfc.Net.Transport
Assembly: DRIT.Mail.dll
Syntax
public interface ITextProtocolTransport : IDisposable
Properties
View SourceIsConnected
Gets a value indicating whether the transport is connected.
Declaration
bool IsConnected { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsEncrypted
Gets a value indicating whether the transport is encrypted (TLS).
Declaration
bool IsEncrypted { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
View SourceClose()
Closes the transport. Safe to call multiple times.
Declaration
void Close()
Connect(string, int, TimeSpan)
Connects to the specified host and port.
Declaration
void Connect(string host, int port, TimeSpan timeout)
Parameters
| Type | Name | Description |
|---|---|---|
| string | host | The server hostname. |
| int | port | The server port. |
| TimeSpan | timeout | The connection timeout. |
Connect(string, int, TimeSpan, bool, RemoteCertificateValidationCallback?)
Connects to the specified host and port, optionally using implicit TLS from the moment of TCP connect.
Declaration
void Connect(string host, int port, TimeSpan timeout, bool useImplicitTls, RemoteCertificateValidationCallback? validationCallback)
Parameters
| Type | Name | Description |
|---|---|---|
| string | host | The remote host name or address. |
| int | port | The remote service port. |
| TimeSpan | timeout | The connection timeout. |
| bool | useImplicitTls | A value indicating whether TLS starts immediately after connecting. |
| RemoteCertificateValidationCallback | validationCallback | Optional certificate validation callback for the TLS handshake. |
Flush()
Flushes any buffered write data.
Declaration
void Flush()
ReadBytes(int)
Reads exactly count bytes from the transport.
Used by IMAP for literal {N} data blocks.
Declaration
byte[] ReadBytes(int count)
Parameters
| Type | Name | Description |
|---|---|---|
| int | count | The number of bytes to read. |
Returns
| Type | Description |
|---|---|
| byte[] | The bytes read. |
ReadLine()
Reads one CRLF-terminated line from the transport.
Declaration
byte[]? ReadLine()
Returns
| Type | Description |
|---|---|
| byte[] | The line content (without the trailing CRLF) as bytes, or null if the connection was closed and no data remains. |
UpgradeToSsl(string, RemoteCertificateValidationCallback?)
Upgrades the current connection to TLS (STARTTLS / STLS).
Declaration
void UpgradeToSsl(string host, RemoteCertificateValidationCallback? validationCallback)
Parameters
| Type | Name | Description |
|---|---|---|
| string | host | The server hostname, used for certificate validation. |
| RemoteCertificateValidationCallback | validationCallback | Optional certificate validation callback, or null to use the platform default. |
Write(byte[])
Writes all bytes in the buffer to the transport.
Declaration
void Write(byte[] buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | buffer | The byte data to process. |
Write(byte[], int, int)
Writes a range of bytes to the transport.
Declaration
void Write(byte[] buffer, int offset, int count)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | buffer | The byte data to process. |
| int | offset | The offset within the data. |
| int | count | The count value. |