Click here to Skip to main content
15,886,026 members
Articles / Database Development / SQL Server

Ready-to-use Mass Emailing Functionality with C#, .NET 2.0, and Microsoft® SQL Server 2005 Service Broker

Rate me:
Please Sign up or sign in to vote.
4.84/5 (40 votes)
7 Sep 200613 min read 297.7K   4.6K   210  
This paper demonstrates an extensible mass emailing framework (Smart Mass Email SME). The demo implementation uses cutting edge .NET technologies available today such as C#, .NET 2.0, Microsoft® SQL Server 2005 Service Broker, MS Provider Pattern, Enterprise Library January 2006 etc.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <sectionGroup name="smartMassEmail.providers">
      <section name="emailQueue" type="SmartMassEmail.Providers.EmailQueueConfigurationHandler, Providers" />
      <section name="emailDeQueue" type="SmartMassEmail.Providers.EmailDeQueueConfigurationHandler, Providers" />
      <section name="emailDispatch" type="SmartMassEmail.Providers.EmailDispatchConfigurationHandler, Providers" />
      <section name="processFailure" type="SmartMassEmail.Providers.ProcessFailureConfigurationHandler, Providers" />
      <section name="emailTemplate" type="SmartMassEmail.Providers.EmailTemplateConfigurationHandler, Providers" />
    </sectionGroup>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>
    <section name="cachingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerSettings, Microsoft.Practices.EnterpriseLibrary.Caching, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>
    <section name="netTiersService" type="SmartMassEmail.Data.Bases.NetTiersServiceSection, SmartMassEmail.Data" allowDefinition="MachineToApplication" restartOnExternalChanges="true"/>
  </configSections>
  <smartMassEmail.providers>
    <emailQueue defaultProvider="Sql2000EmailQueueProvider">
      <providers>
        <add name="Sql2000EmailQueueProvider" type="SmartMassEmail.ImplementedProviders.Sql2000EmailQueueProvider, SmartMassEmail.ImplementedProviders" />
        <add name="Sql2005EmailQueueProvider" type="SmartMassEmail.ImplementedProviders.Sql2005EmailQueueProvider, SmartMassEmail.ImplementedProviders" />
      </providers>
    </emailQueue>
    <emailDeQueue defaultProvider="Sql2000EmailDeQueueProvider">
      <providers>
        <add name="Sql2000EmailDeQueueProvider" type="SmartMassEmail.ImplementedProviders.Sql2000EmailDeQueueProvider, SmartMassEmail.ImplementedProviders" />
        <add name="Sql2005EmailDeQueueProvider" type="SmartMassEmail.ImplementedProviders.Sql2005EmailDeQueueProvider, SmartMassEmail.ImplementedProviders" />
      </providers>
    </emailDeQueue>
    <emailDispatch defaultProvider="SMTPDotnet2EmailDispatchProvider">
      <providers>
        <add name="SMTPDotnet1EmailDispatchProvider" type="SmartMassEmail.ImplementedProviders.SMTPDotnet1EmailDispatchProvider, SmartMassEmail.ImplementedProviders" />
        <add name="SMTPDotnet2EmailDispatchProvider" type="SmartMassEmail.ImplementedProviders.SMTPDotnet2EmailDispatchProvider, SmartMassEmail.ImplementedProviders" />
      </providers>
    </emailDispatch>
    <processFailure defaultProvider="Sql2000ProcessFailureProvider">
      <providers>
        <add name="Sql2000ProcessFailureProvider" type="SmartMassEmail.ImplementedProviders.Sql2000ProcessFailureProvider, SmartMassEmail.ImplementedProviders" />
        <add name="Sql2005ProcessFailureProvider" type="SmartMassEmail.ImplementedProviders.Sql2005ProcessFailureProvider, SmartMassEmail.ImplementedProviders" />
      </providers>
    </processFailure>
    <emailTemplate defaultProvider="FileSystemEmailTemplateProvider">
      <providers>
        <add name="FileSystemEmailTemplateProvider" type="SmartMassEmail.ImplementedProviders.FileSystemEmailTemplateProvider, SmartMassEmail.ImplementedProviders" />
      </providers>
    </emailTemplate>
  </smartMassEmail.providers>
  <loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
    <listeners>
      <add fileName="log\trace.log" header="----------------------------------------" footer="----------------------------------------" formatter="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" name="FlatFile TraceListener"/>
      <add fileName="log\debug.log" header="----------------------------------------" footer="----------------------------------------" formatter="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" name="FlatFile DebugListener"/>
      <add fileName="log\WebpageError.log" header="----------------------------------------" footer="----------------------------------------" formatter="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" name="FlatFile WebPageErrorListener"/>
      <add fileName="log\Error.log" header="----------------------------------------" footer="----------------------------------------" formatter="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" name="FlatFile ErrorListener"/>
      <add fileName="log\WebServiceError.log" header="----------------------------------------" footer="----------------------------------------" formatter="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" name="FlatFile WebServiceErrorListener"/>
      <add source="Enterprise Library Logging" formatter="Text Formatter" log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" name="Formatted EventLog TraceListener"/>
    </listeners>
    <formatters>
      <add template="Timestamp: {timestamp}&#xA;Message: {message}&#xA;Category: {category}&#xA;Priority: {priority}&#xA;EventId: {eventid}&#xA;Severity: {severity}&#xA;Title:{title}&#xA;Machine: {machine}&#xA;Application Domain: {appDomain}&#xA;Process Id: {processId}&#xA;Process Name: {processName}&#xA;Win32 Thread Id: {win32ThreadId}&#xA;Thread Name: {threadName}&#xA;Extended Properties: {dictionary({key} - {value}&#xA;)}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" name="Text Formatter"/>
    </formatters>
    <categorySources>
      <add switchValue="All" name="Debug">
        <listeners>
          <add name="FlatFile DebugListener"/>
        </listeners>
      </add>
      <add switchValue="All" name="ErrorWebPage">
        <listeners>
          <add name="FlatFile WebPageErrorListener"/>
        </listeners>
      </add>
      <add switchValue="All" name="Error">
        <listeners>
          <add name="FlatFile ErrorListener"/>
        </listeners>
      </add>
      <add switchValue="All" name="ErrorWebService">
        <listeners>
          <add name="FlatFile WebServiceErrorListener"/>
        </listeners>
      </add>
      <add switchValue="All" name="General">
        <listeners>
          <add name="FlatFile TraceListener"/>
        </listeners>
      </add>
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events"/>
      <notProcessed switchValue="All" name="Unprocessed Category"/>
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="Formatted EventLog TraceListener"/>
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>
  <cachingConfiguration defaultCacheManager="Cache Manager">
    <cacheManagers>
      <add expirationPollFrequencyInSeconds="60" maximumElementsInCacheBeforeScavenging="1000" numberToRemoveWhenScavenging="10" backingStoreName="Null Storage" name="Cache Manager"/>
    </cacheManagers>
    <backingStores>
      <add encryptionProviderName="" type="Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.NullBackingStore, Microsoft.Practices.EnterpriseLibrary.Caching, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" name="Null Storage"/>
    </backingStores>
  </cachingConfiguration>
  <dataConfiguration defaultDatabase="SmartMassEmailConnectionString"/>
  <connectionStrings>
    <add name="SmartMassEmailConnectionString" connectionString="Data Source=servername;Initial Catalog=SmartMassEmailDB;User ID=sa;password=password" providerName="System.Data.SqlClient"/>
    <add name="SmartMassEmailConnectionString2005" connectionString="Data Source=servername;Initial Catalog=SmartMassEmailDB2005;User Id=sa;Password=password;" />
  </connectionStrings>

  <netTiersService defaultProvider="SqlNetTiersProvider">
    <providers>
      <add name="SqlNetTiersProvider" type="SmartMassEmail.Data.SqlClient.SqlNetTiersProvider, SmartMassEmail.Data.SqlClient" connectionStringName="SmartMassEmailConnectionString" useStoredProcedure="false" providerInvariantName="System.Data.SqlClient"/>
    </providers>
  </netTiersService>
  
  <appSettings>
    <!--   User application and configured property settings go here.-->
    <!--   Example: <add key="settingName" value="settingValue"/> -->
    <add key="TemplateFolderPath" value="C:\DotNetWorkFolder2005\SmartMassEmail\Src\SmartMassEmail.WebApplication\Templates\"/>
    <add key="SitePrefix" value="http://localhost:1569/"/>
    <!--smtp section-->
    <add key="SmtpServer" value="webmail.domain.com"/>
    <add key="SmtpServerUserName" value="username"/>
    <add key="SmtpServerPassword" value="password"/>
    <add key="SmtpPortnumber" value=""/>
    <add key="SmtpServerConnectionLimit" value="3"/>
    <add key="WaitSecondsWhenConnectionLimitExceeds" value="15"/>
    <add key="EmailEncoding" value="utf-8"/>
    <!--smtp section end-->
    <add key="IntervalMinutes" value="0.05" />
  </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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Australia Australia
I have been awarded MVP (Visual C#) for year 2007, 2008, 2009. I am a Microsoft Certified Application Developer (C# .Net). I currently live in Melbourne, Australia. I am a co-founder and core developer of Pageflakes www.pageflakes.com and Founder of Simplexhub, a highly experienced software development company based in Melbourne Australia and Dhaka, Bangladesh. Simplexhub.
My BLOG http://www.geekswithblogs.net/shahed
http://msmvps.com/blogs/shahed/Default.aspx.

Comments and Discussions