Click here to Skip to main content
15,171,439 members
Technical Blog
Posted 23 May 2015

Tagged as



3 bookmarked

Email - Marketing evolution Part 1 - Creating some structure

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
23 May 2015CPOL8 min read
Email - Marketing Part 1 - building the structure.

When I chose topics for my blog I take mainly into consideration ideas that I can deliver within my own resources and think they would help my blog traffic. As I find it rewarding to seeing my blog analytics improving weekly I am constantly on the look for new sources of traffic and improving current ones. Also due to the fact that I never have allocated any marketing budget to this blog, at least so far one can alternatively refer to this blog as the "Do not spend a penny cookbook to internet marketing".

After just 5 months since registration I can clearly see result for the effort put in SEO, even though this blog is powered by the not so mainstream open source blog engine the extended functionalities are paying back. One important thing about Internet Marketing is to increase and improve your traffic sources both paid for and free ones, as I am running this blog as a hobby and prefer spending my cash on booze I tend to favor quick wins that cost nothing but little development time.

Thus, naturally I had to blog about building a good email marketing strategy, yet another traffic source for free quality traffic to your site. Sounds great but let me give you a Warning traffic from Email Marketing is not as straight forward to achieve as sending random emails. It involves in nurturing a mailing list and that alone takes time and effort, optimising its usage is crucial and that is why we speak of a mail list strategy. The good strategy should detail a plan how to obtain and manage subscriptions, use these email lists to attract and keep visitors, and how and when best to promote. In the article by using what is available in blogengine, doing some code alterations and making use of some more development I will experiment with improving the following :

  1. Storing your mailing list
  2. Using your mailing list
  3. Growing your mailing list

The sequence in this plan happens since I use it comes with a very naive version of a newsletter which stores email in an xml file if someone presses the subscribe button.

Newsletter blogfornet join

This is not good enough for me so as a starter I will extend this widget to have the details stored in a proper database table. Once I have all my emails from different sources in one safe place, I will use a service I had created some time ago to auto schedule a mailing strategy, usually such mailing sequences are made up of a welcome email upon joining, followed by a scheduled monthly email AKA newsletters. Than I can proceed to find ways to increase this mailing list by finding news sources like creating a landing page and improving this mail list subscription.

Hmm... Sounds like a very ambitious plan so better get started. My plan is to have it done in 3 articles starting from this first article where we will be creating the part to gather and store the emails in a database.

Why email marketing

Google 200 reasons for email marketing and you will find the answer yet cause some advantages of email marketing are obvious, but for me the main attractions are. First of all is visitor engagement, if this was a profit making site one would call it customer engagement. Thanks to the email a visitor or client can interact with the site in a 2 way conversation like, this takes your site to the next level. Secondly using email marketing you can re-attract visitors to your site and anyone in sales knows that selling to an existing client is much easier than creating a new one. But for me the buzz of exploiting this traffic source is that once you start exploring email marketing send the email is just the tip of the iceberg. There are so many cool things you can do with a mailing list, like tracking, analytics, landing pages, email sequencing, a/b testing ... I am afraid I will be expanding a lot of tools here.

What do you really need is my choice for blogging due to the fact that I can manipulate the code, anyway I seam fit for my needs, and my needs for this email marketing project are beyond an xml with an email address. To be honest I am not particularly proud of the code below as I am still rather new to the blogengine structure and believe that with some more effort I could follow better the architecture and have a newsletter widget that could be both an xml and a database driven, but my ultimate challenge is to have the current project delivered so yes I will follow the 20/80 rule cut a couple of corers.

Storing Emails to the database

So we will start by connecting to the blogEngine to a MSSql database, if you are not using the database storage for blog engine I recommend you do it. It is as simple as running a script found in your blogengine setup folder and changing the web.configuration. Details of this process can be found in the blogEngine FAQ . Storing your blog in a database might make some pages slower at times but having a central relational repository is key to being able to extend your blog as through the connection string several external tools can interact with your blog activity directly through the database.

Once you are successfully persisting to a database you will notice that only the core functionality like the blog, comments and posts are stored in to the database. Next we will add the mail list subscription which currently it is stored in an xml file in the App_data folder called newsletter.xml. Step one is to create the table structure. I have kindly provided the script to add the email table script that needs to be run on your database here . It will create a be_Emails table with the following structure.

CREATE TABLE [dbo].[be_Emails](
[Id] [int] IDENTITY(1,1) NOT NULL,
[BlogId] [uniqueidentifier] NOT NULL,
[Email] [nvarchar](500) NOT NULL,
[Source] [nchar](100) NULL,
[IsActive] [int] NOT NULL,
[Created] [datetime] NULL,

This structure will serve to store the emails coming from any source starting with the current news letter widget. Other sources could include emails supplied during blog posts or eventually the landing page. The blogId will help me keep in line with the structure of blogengine where a guid is used to uniquely identify the blog, email as obviously the email address of the subscriber, source will be the originating source of the email capturing, a flag isActive will help me manage subscribe and unsubscribe functionality and the created field is mainly for auditing.

Altering the Newsletter code to store in db

Once we are done with the database table creation, we will need to alter the code to store the data to this table rather than the xml file. We will alter the Newsletter widget found in the BlogEngine source code Custom\Widgets\Newsletter.

This user control uses XML files to load the save the emails. There is some logic here to load the xml file as to not have duplicate emails and send a welcome email, I will ignore all this code and concentrate on the save email method.

First I will create my own save email Provider that will take care to save the email to the database. Here where I could go a bit more hardcore and provide the ability to use either xml or database but for simplicity stake I will limit my solution to database only yet respecting the current architecture.

In the blogEngine.Code solution under the providers folder I will add a new class called MailListProvider.cs . In this class I will create an AddToMailList(string blogId, string email, string source) public method which will practically run the following parameterized insert query.

"If not Exists(select 1 from be_emails where email = @Email AND IsActive = 1) begin Insert Into be_Emails(BlogId, Email, Source, IsActive, Created)Values(@BlogId, @Email, @Source, @IsActive, @Created) end;"

Obviously to run this query you will need a connection to the database and preferably to follow the current provider syntax. I provided the code for this class here: Mail list provider class

Next you will need to find the code that reads the email address from the widget and stores it in the xml. This is located in the code behind file widget.ascx.cs folder Custom\Widgets\Newsletter. Here we will make a new save method AddEmailToDb(string email)

private void AddEmailToDb(string email)
string source = "newsletter_subscribe";
string blogId = Blog.CurrentInstance.Id.ToString();
var dbMail = new MailListProvider();
dbMail.AddToMailList(blogId, email, source);
callback = "true";

Now in the same class locate the current save method private void AddEmail(string email) and modify it to use the new save to db method

private void AddEmail(string email)

If you run the web application locally you should be able to enter your email in the news letter filed and find it stored in the database select * from [dbo].[be_Emails] . Just in case you need the widget.ascx.cs code can be found here

Altenativly fee free to see the code on my git repository:

Getting more data

Now that we have news letter subscription feeding my mailing list in a structured database I just need to sit and wait for visitors to subscribe but NO. I need a list to get started and I need some emails to go to the next step, so maybe this is not 00% ethicallt correct but the way I see it if you post on my blog using your email it is like accepting to be registered to my news letter...

Well you do not like it I will give you an unsubscribe option but my blog my rules baby. Thus we will extract the emails addresses of persons who posted on my blog as an initial mailing list. You can do this by running a database script to convert your current posts to members of the email list.

insert into [dbo].[be_Emails] ( BlogId, Email, Source, IsActive, Created )
select BlogId, email, 'PostCommentImport',1, commentDate
from [dbo].[be_PostComment] where email like '%@%'

Also I created a new Extension EmailListExtractor so that every time a new comment is posted the email address used will be automatically stored to my mailing list..

public void Comment_Serving(object sender, EventArgs e)
           //Save email .
           string email = ((BlogEngine.Core.Comment) (sender)).Email;
           string source = "postcomment_email";
           string blogId = BlogEngine.Core.Blog.CurrentInstance.Id.ToString();
           var dbMail = new MailListProvider();
           dbMail.AddToMailList(blogId, email, source);

So I have a mailing list in an accessible database, And now comes the fun


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


About the Author

Adrian Cini
Team Leader
Malta Malta
Hello. I am Adrian from Malta, worked in different markets like gaming , marketing, regulatory bodies, government etc. Passionate in Internet marketing, search engine optimization and development frameworks. Love travelling and diving.
See my blog for the latest of my development stories @

Comments and Discussions

-- There are no messages in this forum --