Click here to Skip to main content
15,885,278 members
Articles / Programming Languages / CUDA

A C# SMTP server (receiver)

Rate me:
Please Sign up or sign in to vote.
5.00/5 (14 votes)
17 Sep 2012CPOL9 min read 107.8K   5.6K   37  
A C# SMTP server (receiver).
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <!--
  * HostName        host name used for banner, null = retrieve it from network settings
  
  * ListenAddress:  address to listen on, 0.0.0.0=any (default=127.0.0.1)
  
  * ListenPort:     port # to listen on (default=25 SMTP)
  
  * ReceiveTimeOut  timeout after which a read operation fails (and session is dropped)
                    the default is 8000, that is, 8 seconds, if the client doesn't send
                    in commands or data, it will receive a 4xx "timeout" message and
                    the connection will be dropped; lower the value on very busy boxes,
                    raise it in case you have a slow connection
  
  * MaxSmtpErrors   max number of accepted SMTP errors (invalid commands ...) after reaching
                    this limit, the connection will be dropped with an error message

  * MaxSmtpNoop     max number of "NOOP" commands accepted, same behaviour as for max errors
  
  * MaxSmtpNoop     max number of "VRFY/EXPN" commands accepted, same behaviour as for max errors

  * MaxSmtpRcpt     max number of "RCPT TO" commands accepted, same behaviour as for max errors

  * MaxMessages     max number of messages accepted in a single session (default=10)

  * MaxSessions     max number of parallel sessions; once reached, incoming connections will
                    be rejected (immediately disconnected) until the number of session doesn't
                    drop under this limit, this is useful to avoid being DDoS-ed by a flock of
                    bots issuing a huge number of connection to our box
                    
  * StoreData       if true, the email envelope and DATA are stored into a temporary, unique
                    file, if DoTempFail is true, setting this value will cause the temp fail
                    to be sent out after the DATA has been received (otherwise it will be
                    sent out when receiving the DATA command, see also DoTempFail)

  * StorePath       path used to store the email data (as above), each message will be stored
                    into a file with a unique name, messages headers will the contain some
                    additional headers "X-FakeSMTP-..." containing the session and envelope
                    informations, the folder must be writable, it can be the same path used
                    for LogPath
  
  * MaxDataSize     max size for a mail message (headers and data) only used if StoreData
                    is enabled; in this case, a message bigger than MaxDataSize will cause
                    a 4xx "quota" tempfail message to be returned to the client
                    
  * LogPath         path to store logfiles both related to general program operations and to
                    the sessions/emails; files are named using the current month # so you'll
                    have a max of 12 logfiles, older ones will be automatically overwritten
                    the folder must be writable, it can be the same path used for StorePath
  
  * VerboseLogging  if true, the logfile will also contain the command and replies, this is
                    useful when using the program to test a mail sending application or to
                    diagnose a mail issue (note: that the DATA part won't be logged)

  * BannerDelay     delay (milliseconds) before emitting the SMTP server initial "banner" this may
                    help to slowdown spamsending bots although rising the value too much may cause
                    problems since you may end up with a bunch of sessions waiting for the banner
                    for details see http://wiki.asrg.sp.am/wiki/Early_talker_detection
  
  * ErrorDelay      delay (milliseconds) to emit a response after an error, the delay is multiplied
                    by the errors count so, the more errors the higher the delay (up to max errors)

  * DoTempFail      if true, at or after the DATA command (see StoreData) the server will emit a 
                    4xx tempfail message and drop the connection, this is useful if you want to
                    use the program to setup an "MX sandwich" (aka "nolisting")
                    
  * DoEarlyTalk     if true, enables checking for the so called "early talkers" that is SMTP
                    senders which don't wait for the server banner or reply but keep sending
                    in commands/data; those clients are usually spambots and enabling this check
                    will reject them (checks are performed before both the banner and each reply
                    are sent out to the remote client)
                    
  * RWLproviders    comma separated list of DNS whitelist providers against which the incoming
                    IP is checked; if listed, the blacklist checks will be skipped; set this to
                    null to disable this check
  
  * RBLproviders    comma separated list of DNS blacklist providers against which the incoming
                    IP is checked; if listed and if StoreData is disabled, the connection will
                    be dropped with a tempfail (4xx) error message, set this to null to disable
                    this check
                    
  * LocalDomains    pathname of a text file containing the list of locally handled domains, one
                    on each line; if empty, all domains will be accepted, otherwise the program
                    will emit a "rely denied" error in case an "RCPT TO" targets a domain which
                    isn't included in this list
                    
  * LocalMailBoxes  pathname of a text file containing the list of locall handled email addresses
                    one on each line; if empty all addresses will be accepted, otherwise the program
                    will emit an "invalid address" if an "RCPT TO" targets an address which isn't
                    included in this list
  -->
  <appSettings>
    <add key="HostName" value=""/>
    <add key="ListenAddress" value="127.0.0.1"/>
    <add key="ListenPort" value="25"/>
    <add key="ReceiveTimeOut" value="8000"/>
    <add key="MaxSmtpErrors" value="4"/>
    <add key="MaxSmtpNoop" value="7"/>
    <add key="MaxSmtpVrfy" value="10"/>
    <add key="MaxSmtpRcpt" value="100"/>
    <add key="MaxMessages" value="10"/>
    <add key="MaxSessions" value="16"/>
    <add key="StoreData" value="True"/>
    <add key="StorePath" value=""/>
    <add key="MaxDataSize" value="2097152"/>
    <add key="LogPath" value=""/>
    <add key="VerboseLogging" value="False"/>
    <add key="BannerDelay" value="1000"/>
    <add key="ErrorDelay" value="500"/>
    <add key="DoTempFail" value="False"/>
    <add key="DoEarlyTalk" value="True"/>
    <add key="RWLproviders" value="swl.spamhaus.org,iadb.isipp.com"/>
    <add key="RBLproviders" value="zen.spamhaus.org,bb.barracudacentral.org,ix.dnsbl.manitu.net,bl.spamcop.net,combined.njabl.org"/>
    <add key="LocalDomains" value=""/>
    <add key="LocalMailBoxes" value=""/>
  </appSettings>
</configuration>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions