speed subash

speed subash

  • NA
  • 1
  • 1.1k

error: smtp server cant be connected

Jan 21 2015 1:35 AM
I am getting a error while compiling my program, this program is written to send a automatic mail after 10 seconds. But an error occurs and that says smtp server cant be connected...please help me with correct response.. and the following is the code which i wrote
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.ComponentModel;// for backgroundworker class
using System.Net;
using System.Net.Mail;
using System.Threading;
public partial class _Default : System.Web.UI.Page
{
    BackgroundWorker bw;
    protected void Page_Load(object sender, EventArgs e)
    {
        bw = new BackgroundWorker();
        bw.DoWork += new DoWorkEventHandler(bw_DoWork);
        bw.WorkerSupportsCancellation = true;
        bw.WorkerReportsProgress = false;
    }
    public void SendMail()
    {
        MailMessage msg = new MailMessage();
        msg.From = new MailAddress("[email protected]");
        msg.To.Add("[email protected]");
        msg.Body = "Testing the automatic mail";
        msg.IsBodyHtml = true;
        msg.Subject = "Movie Data";
        SmtpClient smt = new SmtpClient("smtp.gmail.com");
        smt.Port = 587;
        smt.Credentials = new NetworkCredential("[email protected]", "zzzzzzzz");
        smt.EnableSsl = true;
        smt.Send(msg);
        string script = "<script>alert('Mail Sent Successfully');self.close();</script>";
        this.ClientScript.RegisterClientScriptBlock(this.GetType(), "sendMail", script);
    }
    public void bw_DoWork(object sender, DoWorkEventArgs e)
    {
        SendMail();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        DateTime current_time = DateTime.Now;
        current_time = current_time.AddSeconds(10);
        Thread.Sleep(10000);
        if (current_time == DateTime.Now)
        {
            bw.RunWorkerAsync();
        }
    }
}

please reply as soon as possible to my email id,...
Thanks in advance.... 

Answers (2)