Click here to Skip to main content
15,885,278 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.
// =====================================================================================
// Copyright � 2005 by Shahed Khan. All rights are reserved.
// 
// If you like this code then feel free to go ahead and use it.
// The only thing I ask is that you don't remove or alter my copyright notice.
//
// Your use of this software is entirely at your own risk. I make no claims or
// warrantees about the reliability or fitness of this code for any particular purpose.
// If you make changes or additions to this code please mark your code as being yours.
// 
// website , email shahed.khan@gmail.com
// =====================================================================================

using System;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Text;
using SmartMassEmail.Providers;
using System.Configuration;
using SmartMassEmail.Entities;
using SmartMassEmail.Data.SqlClient;
using SmartMassEmail.Data;

namespace SmartMassEmail.ImplementedProviders
{
    public class Sql2000EmailQueueProvider: EmailQueueProvider
    {
        public Sql2000EmailQueueProvider( ) 
		{
		}

		#region EmailQueue specific functions
        public override bool Send(EmailMessage message)
		{
            if (message != null)
            {
                SmartMassEmail.Data.Bases.NetTiersProvider p = DataRepository.Provider;
                DataRepository rep = new DataRepository();
                
                TransactionManager transaction = rep.CreateTransaction();
                try
                {
                    transaction.BeginTransaction();
                    DataRepository.EmailMessageProvider.Insert(transaction, message);
                    if (message.EmailMessageDetailCollection != null)
                    {
                        if (message.EmailMessageDetailCollection.Count > 0)
                            DataRepository.EmailMessageDetailProvider.Insert(transaction, message.EmailMessageDetailCollection);
                    }
                    transaction.Commit();
                    return true;
                }
                catch
                {
                    if (transaction != null)
                        if (transaction.IsOpen)
                        {
                            transaction.Rollback();
                            transaction = null;
                        }
                }
            }
			return false;
		}

		
		#endregion

		#region Provider specific behaviors
		public override void Initialize(string name, NameValueCollection configValue) {

		}

		public override string Name {
			get {
				return null;
			}
		}
		#endregion
    }
}

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