Click or drag to resize
MimeKit

ProtocolLogger Class

A default protocol logger for logging the communication between a client and server.
Inheritance Hierarchy
SystemObject
  MailKitProtocolLogger

Namespace: MailKit
Assembly: MailKit (in MailKit.dll) Version: 4.3.0
Syntax
C#
public class ProtocolLogger : IProtocolLogger, 
	IDisposable

The ProtocolLogger type exposes the following members.

Constructors
 NameDescription
Public methodProtocolLogger(Stream, Boolean) Initializes a new instance of the ProtocolLogger class.
Public methodCode exampleProtocolLogger(String, Boolean) Initializes a new instance of the ProtocolLogger class.
Top
Properties
 NameDescription
Public propertyAuthenticationSecretDetector Get or set the authentication secret detector.
Public propertyClientPrefix Get or set the client prefix to use when logging client messages.
Public propertyStatic memberDefaultClientPrefix Get or set the default client prefix to use when creating new ProtocolLogger instances.
Public propertyStatic memberDefaultServerPrefix Get or set the default server prefix to use when creating new ProtocolLogger instances.
Public propertyLogTimestamps Get or set whether timestamps should be logged.
Public propertyRedactSecrets Get or set whether or not authentication secrets should be redacted.
Public propertyServerPrefix Get or set the server prefix to use when logging server messages.
Public propertyStream Get the log stream.
Public propertyTimestampFormat Get or set the date and time serialization format that should be used when logging timestamps.
Top
Methods
 NameDescription
Public methodDispose Releases all resource used by the ProtocolLogger object.
Protected methodDispose(Boolean) Releases the unmanaged resources used by the ProtocolLogger and optionally releases the managed resources.
Public methodEquals
(Inherited from Object)
Protected methodFinalize Releases unmanaged resources and performs other cleanup operations before the ProtocolLogger is reclaimed by garbage collection.
(Overrides ObjectFinalize)
Public methodGetHashCode
(Inherited from Object)
Public methodGetType
(Inherited from Object)
Public methodLogClient Logs a sequence of bytes sent by the client.
Public methodLogConnect Logs a connection to the specified URI.
Public methodLogServer Logs a sequence of bytes sent by the server.
Protected methodMemberwiseClone
(Inherited from Object)
Public methodToString
(Inherited from Object)
Top
Remarks
A default protocol logger for logging the communication between a client and server.
Example
C#
public static void SendMessage (MimeMessage message)
{
    using (var client = new SmtpClient (new ProtocolLogger ("smtp.log"))) {
        client.Connect ("smtp.gmail.com", 465, SecureSocketOptions.SslOnConnect);

        client.Authenticate ("username", "password");

        client.Send (message);

        client.Disconnect (true);
    }

    // Example log:
    // 
    // Connected to smtps://smtp.gmail.com:465/
    // S: 220 smtp.gmail.com ESMTP w81sm22057166qkg.43 - gsmtp
    // C: EHLO [192.168.1.220]
    // S: 250-smtp.gmail.com at your service, [192.168.1.220]
    // S: 250-SIZE 35882577
    // S: 250-8BITMIME
    // S: 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
    // S: 250-ENHANCEDSTATUSCODES
    // S: 250-PIPELINING
    // S: 250-CHUNKING
    // S: 250 SMTPUTF8
    // C: AUTH PLAIN AHVzZXJuYW1lAHBhc3N3b3Jk
    // S: 235 2.7.0 Accepted
    // C: MAIL FROM:<from.addr@gmail.com>
    // C: RCPT TO:<to.addr@gmail.com>
    // S: 250 2.1.0 OK w81sm22057166qkg.43 - gsmtp
    // S: 250 2.1.5 OK w81sm22057166qkg.43 - gsmtp
    // C: DATA
    // S: 354  Go ahead w81sm22057166qkg.43 - gsmtp
    // C: From: "LastName, FirstName" <from.addr@gmail.com>
    // C: Date: Thu, 27 Dec 2018 10:55:18 -0500
    // C: Subject: This is a test message
    // C: Message-Id: <C7GVXWE3C6U4.7ZQ0K9OUHTDP1@MADUNLA-SP4.northamerica.corp.microsoft.com>
    // C: To: "LastName, FirstName" <to.addr@gmail.com>
    // C: MIME-Version: 1.0
    // C: Content-Type: multipart/alternative; boundary="=-CToJI+AD2gS6z+fFlzDvhg=="
    // C: 
    // C: --=-CToJI+AD2gS6z+fFlzDvhg==
    // C: Content-Type: text/plain; charset=utf-8
    // C: Content-Transfer-Encoding: quoted-printable
    // C: 
    // C: This is the text/plain message body.
    // C: --=-CToJI+AD2gS6z+fFlzDvhg==
    // C: Content-Type: text/html; charset=utf-8
    // C: Content-Transfer-Encoding: quoted-printable
    // C: 
    // C: <html><body><center>This is the <b>text/html</b> message body.</center></body></html>
    // C: --=-CToJI+AD2gS6z+fFlzDvhg==--
    // C: 
    // C: .
    // S: 250 2.0.0 OK 1545926120 w81sm22057166qkg.43 - gsmtp
    // C: QUIT
    // S: 221 2.0.0 closing connection w81sm22057166qkg.43 - gsmtp
}
See Also