简体   繁体   中英

help with creating windows server

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.

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.

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM