Click or drag to resize

Server Class

Represents the entire Server Implementation, with a Listener and a Router working together.
Inheritance Hierarchy
SystemObject
  SMTPRouterServer

Namespace:  SMTPRouter
Assembly:  SMTPRouter (in SMTPRouter.dll) Version: 1.0.0.4
Syntax
public sealed class Server

The Server type exposes the following members.

Constructors
Properties
  NameDescription
Public propertyDestinationSmtps
A Dictionary containing the Smtp Configuration based on a Key name
Public propertyFolders
A structure representing the queue folders
Public propertyIsPaused
Defines whether the routing process is Paused or Running
Public propertyListener
Reference to the Listener used by the Server
Public propertyMessageLifespan
The TimeSpan a message is stil considered valid. By default, a message lasts 15 minutes after its creation time
Public propertyMessagePurgeLifespan
The TimeSpan a message remains on queues. By default a message remains there for 90 days before being purged.
Public propertyPorts
Ports where the SMTP Service will be available
Public propertyQueueName
The name of the queue
Public propertyQueuePath
The root directory where the queues will be located
Public propertyRequiresAuthentication
Defines whether the SMTP Requires authentication
Public propertyRouter
Reference to the Router used by the Server
Public propertyRoutingRules
List of Rules to be applied when routing messages
Public propertyServerName
Name of the Server where the services will run
Public propertyUseSSL
Defines whether it's necessary to use SSL or not
Top
Methods
  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodStartAsync
Starts the Server Listener and Router
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Events
  NameDescription
Public eventGeneralError
Event triggered when a general error happens on the processing
Public eventListeningStarted
Event triggered when the Listener started to listen to smtp messages
Public eventMessageNotRouted
Event triggered when a message could not be routed successfully
Public eventMessagePurging
Event triggered when a message is about to be purged by the system.
Public eventMessageReceived
Event triggered when a message is received
Public eventMessageRoutedSuccessfully
Event triggered when a message is routed successfully
Public eventMessagesPurged
Event triggered after messages are purged
Public eventSessionCommandExecuting
Event trigered when a SMTP Command is being executed
Public eventSessionCompleted
Event triggered when a SMTP Session is closed
Public eventSessionCreated
Event triggered when a SMTP Session is created
Top
Remarks
This class implements the entire communication between the Listener and the Router
Examples
Use the code below to initialize an instance of the Server:
// Creates the Server
var server = new SMTPRouter.Server("localhost", 25, false, false, "SMTPRouter", "C:\\SMTPRouter\\Queues")
{
    MessageLifespan = new TimeSpan(0, 15, 0),
    RoutingRules = new List<Models.RoutingRule>()
    {
        new Models.MailFromDomainRoutingRule(10, "gmail.com", "gmail"),
        new Models.MailFromDomainRoutingRule(20, "hotmail.com", "hotmail")
    },
    DestinationSmtps = new Dictionary<string, Models.SmtpConfiguration>
    {
        { "gmail", new Models.SmtpConfiguration()
            {
                Host = "smtp.gmail.com",
                Description = "Google Mail SMTP",
                Port = 587,
                RequiresAuthentication = true,
                User = "user@gmail.com",
                Password = "",
            }
        },
        { "hotmail", new Models.SmtpConfiguration()
            {
                Host = "smtp.live.com",
                Description = "Hotmail SMTP",
                Port = 587,
                RequiresAuthentication = true,
                User = "user@hotmail.com",
                Password = "",
            }
        }
    },
};

// Hook Events
server.SessionCreated += Server_SessionCreated;
server.SessionCommandExecuting += Server_SessionCommandExecuting;
server.SessionCompleted += Server_SessionCompleted;
server.ListeningStarted += Server_ListeningStarted;
server.MessageReceived += Server_MessageReceived;
server.MessageRoutedSuccessfully += Server_MessageRoutedSuccessfully;
server.MessageNotRouted += Server_MessageNotRouted;

// Initialize Services
Task.WhenAll(server.StartAsync(CancellationToken.None)).ConfigureAwait(false);
See Also