Friday, February 10, 2012

Sending Group Emails in asp.net

private void GetApplnumber()
{
    if (Session["userData"] == null)
    {
        string strmsg = "Session has been expire, Please login again to continue";
        string stralert = "<script language=javascript>alert('" +strmsg + "');";
        stralert += "window.location='../login.aspx'</script>";
        Page.RegisterClientScriptBlock("alert", stralert);
    }
    else
    {
        user = (User1)Session["userData"];
        Executive = user.UserID.ToString();
        string applno = string.Empty;
        DataSet ds = new DataSet();
        ds = BussinessLayer.SendEmail(Executive, applno);  //getting data from database throug              BussinessLayer
        if (ds.Tables[0].Rows.Count > 0)
        {
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                if (dr["Email"].ToString() != string.Empty)
                {
                    Emails = Emails + dr["Email"].ToString() + ";" ;
                }
            }
        }
    }
}

//button click

protected void btnsend_Click(object sender, EventArgs e)
    {
        try
        {
            GetApplnumber();
            string id =Emails.ToString();
            string[] stremail = id.Split(';');
            for (int i = 0; i < stremail.Length - 1; i++)
            {
                MailMessage mailmm = new MailMessage();
                mailmm .From = new MailAddress("abc@def.com");
                mailmm .To.Add(new MailAddress(stremail[i].ToString()));
                mailmm .Subject = txtsubject.Text;
                mailmm .Body = txtbody.Text;
                mailmm .IsBodyHtml = true;
                SmtpClient client = new SmtpClient();
                client.EnableSsl = true;
                client.Timeout = 400000;
                client.Send(mailmm );
            }
                   
        }
       catch(SmtpException ex)
        {
            lblres.Text = ex.ToString();
        }
             
    }

No comments:

Post a Comment

Comments

Search

Custom Search
Protected by Copyscape Plagiarism Software