开发者

how to create window service and use for sending mail

i m creating a library project and want to sending mail automatically for the defaulter(who not return book at time) . for some search on internet i found the window service that help but i can't understand to use properly 1- create a window service with timer that compare current date to sqltable returndate column (how to comp开发者_Python百科are) and if (is true) then send mail automatically. please tell me ho how to implement


  1. Create a new service project (Visual C# / Windows / Windows service)
  2. Double click on the service file in solution explorer.
  3. Right click in the design view of that file and add an installer from the context menu.
  4. Select the service process installer item in the design view and setup the Account property in the Properties window to something like NetworkService or LocalSytem to give the service enough rights for mail network and database operations
  5. In the underlying service class you have the overwritten methods OnStart() and OnStop() to control the behavior of the service. you also can overwrite OnPause(), OnShutdown() and OnContinue()
  6. Use the SmtpClient class from the .NET Framework, if you want to send by SMTP: http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx
  7. Use the console tool installutil.exe from the .NET SDK to install the service:

    installutil.exe -i myService.exe


Don't reinvent the wheel. Since you already probably have the data in SQL, use the built-in db-mail functionality: Database Mail.

Simply have a daily SQL Agent job that scans the table for delinquents and calls sp_send_dbmail for each.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜