How to upload files on server using windows services.
How to upload files on server using windows services and how send mail with attachment using windows services.
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Sumit KumawatRank #4,008 · 372 reputationPosted Oct 26, 2012, 8:58 PM EDT
first you have to create the window service here is ink for creating window service in easy steps.
http://www.aspdotnet-suresh.com/2011/06/creating-windows-service-in-c-or.html
in window service OnStart methoth just put this code for send mail with attachement
protected override void OnStart(string[] args)
{
try { MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); mail.From = new MailAddress("[email protected]"); mail.To.Add("to_address"); mail.Subject = "Test Mail - 1"; mail.Body = "mail with attachment"; System.Net.Mail.Attachment attachment; attachment = new System.Net.Mail.Attachment("your attachment file"); mail.Attachments.Add(attachment); SmtpServer.Port = 587; SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password"); SmtpServer.EnableSsl = true; SmtpServer.Send(mail); MessageBox.Show("mail Send"); } catch (Exception ex) { Console.WriteLine(ex.ToString()); }}
u can see the actual code from below link
http://csharp.net-informations.com/communications/csharp-email-attachment.htm