dimanche 1 mai 2016

Send Mail to respective people on the basis of checkbox checked in asp.net

I have a feature where I want to send mail to different people on the basis of criteria selected. So my requirement is as followed.

I have a checkbox on checking of which my three different options of checkboxes gets visible. Like below

Image

So now what I want is, if I select Option 1 and click on submit button then mail should to the people of Option 1 which are RA 1 and RA 2 respectively.

And if I select the second option, the mail should go to the second option people.

SO How to get the condition for checking whether it should go to Option 1, Option 2 or OPtion 3.

I have written the mail function which is below, just need to write the checkbox check condition. Kindly help

private void SendMail()
{

    string strSql = "My query";

    DataTable table = new DataTable();
    using (OracleConnection ObjPriCon = new OracleConnection(System.Configuration.ConfigurationManager.ConnectionStrings["OracleConn"].ToString()))
    {
        ObjPriCon.Open();
        using (OracleDataAdapter dbdata = new OracleDataAdapter(strSql, ObjPriCon))
        {
            dbdata.Fill(table);
        }
        ObjPriCon.Close();
    }



    string StrPriBody = "My query with dynamic mail format";

    MailMessage mail = new MailMessage();
    mail.Subject = "Prospective booking notification";
    mail.From = new System.Net.Mail.MailAddress("test@test.com");
    SmtpClient smtp = new SmtpClient();
    smtp.Timeout = 1000000;
    smtp.Port = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Port"]);
    smtp.UseDefaultCredentials = true;
    smtp.Host = System.Configuration.
    ConfigurationManager.AppSettings["MailHost1"];
    smtp.Credentials = new NetworkCredential(mail.From.ToString(), "PS123456");
    smtp.EnableSsl = true;
    mail.To.Add(new MailAddress("abc@test.com"));
    mail.IsBodyHtml = true;
    mail.Body = StrPriBody;
    smtp.Send(mail);
     mailYesNo = "N";
    foreach (Attachment attachment in mail.Attachments)
    {
        attachment.Dispose();
    }
}




Aucun commentaire:

Enregistrer un commentaire