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.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sumit KumawatPosted Oct 27, 2012, 12:58 AM
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