views:

45

answers:

4

Hi, i'm ASP.NET programmer and have no experience in creating windows services. Service i need to create should send emails to our customers each specified period of time. This service should solve issue when hundreds of emails are sent at the same time and block SMTP service on the server while there are many periods of time when SMTP is on idle without sending anything.

Idea is to create a service that i will send whole email and address to, inside of the service i will have some type of dataset ( i don't know which one should i use in winforms/winservices) and some basic timer functionality (ie. each 3 seconds get first mail and send it)... Thing is that there are two main types of mails, registration mails which should be main priority and reminder mails (ie. you haven't entered a site for month ) which have low priority. I prefer to create this priority issue with two data sets, when main one is empty less important one sends.

Another issue is how do i access this service from asp.net application on the same server?

How would you write that in code or at least point me how to, i know there are many explanations on MS website on basic services but as i don't know much about issue i prefer having it explained in here.

Thanks for your time.

A: 

I suggest you look at the various email marketing services that are available, many offer APIs or at least an process that you could automate via .Net code. I really would avoid trying to set-up your own mail server as keeping it operational, even when legitimate, is hard as any mistaken abuse will get you black-listed and it takes a long time to get white-listed (lots of ICANN-abiding, legitimate activity) so having to start again from a new IP is frustrating.

Work with the professionals in this space, ensure they follow ICANN processes and procedures (and that you do as well), and you'll find they have everything you need and save you a mountain of hassle.

Lazarus
@Lazarus, thanks. Problem is that my application is quite hard to integrate with external mailing services... I will do that only if i won't have any other option. You're right about many issues with having home-made solution but still time required to integrate such service i don't have.
eugeneK
Building your own solution is going to take you much longer than integrating with an existing one.
Lazarus
A: 

As for creating a web service, there is a ton of examples aout there, just google for "c# windows service example" . Just two examples:

For data exchange: I would store the necessary actions in a database table and scan these tables regularily from the service. Otherwise you could use .NET remoting or message queues or .NET WCF .

hth

Mario

Mario The Spoon
@Mario The Spoon, i did specifically ask not to provide answers with links to create simple services as i can google myself. Although thanks for DB input though i think saving messages in memory will be better.
eugeneK
A: 

First of all, you don't need a windows service at all, if you know how to send an e-mail from your asp.net app. Read on...

I had a problem similar to yours because ISP that I had my site on was having a limit on e-mails that it can deliver in a day. So I created database table with e-mails, and stored them in there, and created one web page that checked the limits that are in effect, determined if it's safe to send an e-mail, and sends it if it is.

After sending (or not sending) - that page slept for a while (you can insert Sleep() into it - don't use any loops because it will consume your CPU) and then triggered itself via http request again, if there is more mail to be sent.

Every page that filled the mail queue also triggered mail sending page, so it doesn't run when queue is in fact empty.

I guess, either that, or you really go for services.

Daniel Mošmondor
@Daniel Mošmondor, your solution has few flaws. One i will need to call this page each period of time while service has an ability to get windows time and use it asynchronously without triggers. Second one is that i need to set Sleep() on current thread which will force me to create one more application so main website will not run into Sleep() mode.
eugeneK
@Eugene: I'm not at all for windows services, but for a guy that is asp.net programmer, you'll have to endure some harsh learning curve and lot of wtf's if you go that way. I know services, am not running from them, but... you'll remember this post when you try to install your service, try to debug it, and so on... :) Maybe I'm ranting here - but hey, even rants can be useful sometimes.
Daniel Mošmondor
@Daniel Mošmondor, you've got a point...
eugeneK
A: 

Create CONSOLE application.

Create 2 queues in the database. For the e-mails.

In console application, poll the queues periodically, and send e-mails when this is appropriate.

Don't go service until you are happy with application as it is.

When debugged completely, create the service, install it and let it run.

Daniel Mošmondor