facing prob's in scheduled mail delivery, windows service for asp.net application
<p>I am creating mail delivery windows service for asp.net application.
here is my code ,the service is starting but it can't be able to send the mail.....so if any one has solution please share.
also i have providing my own gmail credentials but this is not working. </p>

<pre><code>using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Net.Mail;
using System.Timers;


namespace mailservice
{
    public partial class myservice : ServiceBase
    {


        public myservice()
        {
            InitializeComponent();           
        }

        protected override void OnStart(string[] args)
        {
            if (!System.Diagnostics.EventLog.SourceExists("mailservice"))
            {
                System.Diagnostics.EventLog.CreateEventSource("mailservice", "AutoMailLog");
            }
            eventLog1.Source = "mailservice";
            eventLog1.Log = "AutoMailLog";

            eventLog1.WriteEntry("Service Started successfully at:-" + DateTime.Now.ToString());
            System.Timers.Timer time = new System.Timers.Timer();
            time.Start();
            time.Interval = 5000;
            time.Elapsed += time_elapsed;
        }

        public void time_elapsed(object sender, ElapsedEventArgs e)
        {
             eventLog1.WriteEntry("Mail Sending on" + DateTime.Now.ToString());
             SendEmail("dhanraj.patil89@gmail.com", "dhanraj.patil89@gmail.com", "Automatic Mail sending", "Successfully working");
        }

        public bool SendEmail(string strTo, string strFrom, string strSubject, string strBody)
        {
            bool flag = false;
            MailMessage mailMsg = new MailMessage();
            MailAddress mailAddress = null;
                try
                {               
                mailMsg.To.Add(strTo);
                mailAddress = new MailAddress(strFrom);
                mailMsg.From = mailAddress;
                mailMsg.Subject = strSubject;
                mailMsg.Body = strBody;
                SmtpClient smtpClient = new SmtpClient("smtp.gmail.com",587);
                System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("name@gmail.com","***************");
                smtpClient.Credentials = credentials;
                smtpClient.Send(mailMsg);
                flag = true;
              //  smtpClient.EnableSsl = true;
                eventLog1.WriteEntry("Mail Send Successfully");
                }

            catch (Exception ex)
            {
                eventLog1.WriteEntry("Error occured");      
            }

            finally
            {
            mailMsg = null;
            mailAddress = null;
            }
            return flag;
        }

        protected override void OnStop()
        {
            eventLog1.WriteEntry("Mail Service is stopped!");
        }


    }
}
</code></pre>
