Monday, October 22, 2012

Create a service to send a mail automatically in using

In previous post i have given an example on how to send a mail with attachment in this post i will show how to create a service to send automatic email every  day.
Open windows service project -->project menu-->add reference -->system.web(required for mail message class)
Place a timer control ,then set the properties for as below
Using System.Mail;
Time1_elapsed event
int sh=DateTime.Now.Hour;
int sm=DataTime.Now.Minute;
if(sh==9 &&sm==10)
MailMessage mm=new MailMessage()
mm.Body="<h1>Send automatic email</h1>";

Then do the below process:- the service.cs[Design]
2.Right click on in side of service.cs design-->Add installer
obs:Then two new control will be added
3.service process installer-->right click-->properties-->account=Local system
4.Service Installer --><Right click-->Properties -->service name=P2
5.Build the project(Build-->Build solution)
obs:WS2.exe created under D:c197/ws2/bin/Debug folder with a service called P2

Open .Net command prompt and type as follows ar c:> drive
 Install util -i 197/ws2/bin/debug/ws2.exe

open service(start-->run-->services.msc-->right click on P2-->start

Obs:P2 service will be executed sharp settled time and a mail will be delivered

No comments: