473,320 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Windows Service with email

375 256MB
Hello

I have done a windows service. It works perfectly.
Now my requirement is

When a system logs on and logs off
1. It should send an email(to a user)
2. It should just make a acknowledgment that the windows service started.


Kindly provide me with links and tutorials for the same

Thanks
cmrhema
Jul 20 '07 #1
3 1122
RoninZA
78
To send e-mail in VS2005 with C# you need to use code that looks more or less like the following:

Expand|Select|Wrap|Line Numbers
  1. using System.Net.Mail;
  2. .
  3. .
  4. private void sendMail(string address, string message)
  5. {
  6.     if (address.Trim().Length == 0) return;
  7.  
  8.     try
  9.     {
  10.         MailAddress toAddress = new MailAddress(address);
  11.         MailAddress fromAddress = new MailAddress(new System.Configuration.AppSettingsReader().GetValue("SMTPMailAddress", typeof(string)).ToString());
  12.  
  13.         MailAddressCollection addresses = new MailAddressCollection();
  14.         addresses.Add(toAddress);
  15.  
  16.         MailMessage msg = new MailMessage(fromAddress, toAddress);
  17.  
  18.         msg.Subject = "Message Subject";
  19.         msg.Body = message;
  20.         msg.IsBodyHtml = true;
  21.  
  22.         SmtpClient mail = new SmtpClient(new System.Configuration.AppSettingsReader().GetValue("SMTPServerName", typeof(string)).ToString());
  23.  
  24.         mail.Send(msg);
  25.     }
  26.     catch { }
  27. }
  28.  
Note that SMTP server and from addresses are retrieved from the config file app settings section. There are a whole lot of other properties that you can set in the SmtpClient object for authentication and the like.
Jul 20 '07 #2
RoninZA
78
Sorry, I missed the acknowledgement part - because Windows Services generally run unattended, it is NOT wise to display Messageboxes on the UI (I don't know if this is even possible). Although services' successful starting and stopping get logged in the OS event log, I generally like to create log files to log errors, and any messages that may be of interest.
Jul 20 '07 #3
cmrhema
375 256MB
Sorry, I missed the acknowledgement part - because Windows Services generally run unattended, it is NOT wise to display Messageboxes on the UI (I don't know if this is even possible). Although services' successful starting and stopping get logged in the OS event log, I generally like to create log files to log errors, and any messages that may be of interest.
Thanks RoninZA
I am working on it write know.
Also required to do some more operations in it.
I will let you all know when the problem arises
Thanks again
Jul 22 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Keith | last post by:
I'm in the same boat as the fellow who posted this message back in August: Title : Windows Service, How does one make a service "fail" properly? Author : Ross Bennett Group :...
3
by: belgiozen | last post by:
Hi, I have a working windows service,it is looking for files on the disk and when some of the files are cupdated it calls an executable. But it takes a lot of time(about 10 minutes) to run the...
7
by: Mike | last post by:
I want to create a windows service that will monitor another window service. what i need for the service to do is, if a service is stopped I need it to start the service back up example: ...
7
by: Robert May | last post by:
I have an application that uses the Ax web browser object. When I call the IHTMLElement.click() method on an input button (<input type="submit"> or <input type="button">), the click fires...
9
by: SP | last post by:
Hi All, I wrote a windows service which is supposed to stop after specified amount of time. I am calling OnStop() after specified time. OnStop() methods executed but I dont see the service...
3
by: Nathan Kovac | last post by:
I have a feeling I am missing something simple, but I just can't find it. Perhaps someone can give me a lead on where to look. I will describe the issue then post my code to the web service. My...
1
by: benmorganpowell | last post by:
I have a small windows service which connects to a POP3 server at defined intervals, scans the available messages, extracts the required information and inserts the data into a SQL database. I am...
4
by: WinDev | last post by:
We are trying to build a system where we have a Windows Service do some manipulation of data, and then sending the data to a Windows App. I had posted a question of how we should do this and was...
1
by: noah.blumenthal | last post by:
I wrote a windows service in c# (applause) and now I want to add the ability to edit its settings. Basically this service checks an email account at certain intervals and forwards the emails to...
7
by: =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post by:
我们现在遇到一个问题,通过wcf创建的webservice,选择windows service作为宿主,采用java作为客户端调用成功,但是无法使用asp.net ajax调用。...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shllpp 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.