private void SendMail()
    {
        EmailDetails      details = new EmailDetails();
        IncentiveBusiness b       = new IncentiveBusiness();

        SendMailObject obj = new SendMailObject();
        Business       e   = new Business();

        try
        {
            bool   resultv  = false;
            int    rowIndex = 0;
            string emailid  = null;
            details.Module = "IPE";
            string AuthorName = null;
            string Isstudent  = null;
            details.EmailSubject = "Incentive Point Adjustment";
            string empcode = txtboxMemberId.Text;
            string type    = e.selectMemberType(empcode, txtReferenceId.Text);
            if (type == "M")
            {
                //Isstudent = "N";
                emailid               = b.SelectAuthorEmailId(empcode);
                AuthorName            = b.SelectAuthorName(empcode);
                Session["AuthorName"] = AuthorName;
                if (emailid == "")
                {
                    int result;
                    //string AuthorName;
                    AuthorName = b.SelectAuthorName(empcode);
                    result     = e.insertEmailtrackerIncentive(AuthorName, details, txtReferenceId.Text);
                }
            }
            else
            {
                //Isstudent = "S";
                emailid               = b.SelectStudentEmailId(empcode, txtReferenceId.Text);
                AuthorName            = b.SelectStudentAuthorName(empcode, txtReferenceId.Text);
                Session["AuthorName"] = AuthorName;
                if (emailid == "")
                {
                    int result;

                    AuthorName = b.SelectStudentAuthorName(empcode, txtReferenceId.Text);
                    result     = e.insertEmailtrackerIncentive(AuthorName, details, txtReferenceId.Text);
                    //Session["AuthorName"] = AuthorName;
                }
            }

            details.FromEmail = ConfigurationManager.AppSettings["FromAddress"].ToString();

            if (emailid != "")
            {
                details.ToEmail = emailid;
            }
            string hremailid = b.SelectHRMailID(empcode, type, txtReferenceId.Text);

            string InstWiseHRMailid = b.SelectInstwiseHRMailid(empcode, type, txtReferenceId.Text);
            if (details.ToEmail != null && details.ToEmail != "")
            {
                if (InstWiseHRMailid != null)
                {
                    if (InstWiseHRMailid != "")
                    {
                        if (details.ToEmail != null)
                        {
                            details.ToEmail = details.ToEmail + "," + InstWiseHRMailid;
                        }
                        else
                        {
                            details.ToEmail = InstWiseHRMailid;
                        }
                    }
                    else
                    {
                        // details.ToEmail = details.ToEmail;
                    }
                }
                else
                {
                    // details.ToEmail = details.ToEmail;
                }
            }
            else
            {
                if (InstWiseHRMailid != null)
                {
                    if (InstWiseHRMailid != "")
                    {
                        if (details.ToEmail != null)
                        {
                            details.ToEmail = InstWiseHRMailid;
                        }
                        else
                        {
                            details.ToEmail = InstWiseHRMailid;
                        }
                    }
                    else
                    {
                        // details.ToEmail = details.ToEmail;
                    }
                }
                else
                {
                    // details.ToEmail = details.ToEmail;
                }
            }
            ArrayList list = new ArrayList();
            list = b.SelectHODMailid(empcode, type, txtReferenceId.Text);
            for (int j = 0; j < list.Count; j++)
            {
                if (j == 0)
                {
                    if (list[j].ToString() != "")
                    {
                        details.HODmailid = list[j].ToString();
                    }
                }
                else
                {
                    if (list[j].ToString() != "")
                    {
                        details.HODmailid = details.HODmailid + ',' + list[j].ToString();
                    }
                }
            }
            if (details.ToEmail != null && details.ToEmail != "")
            {
                if (hremailid != null)
                {
                    if (hremailid != "")
                    {
                        details.ToEmail = details.ToEmail + "," + hremailid;
                    }
                    else
                    {
                        // details.ToEmail = details.ToEmail;
                    }
                }
                else
                {
                    // details.ToEmail = details.ToEmail;
                }
            }
            else
            {
                if (hremailid != null)
                {
                    if (hremailid != "")
                    {
                        details.ToEmail = hremailid;
                    }
                    else
                    {
                        // details.ToEmail = details.ToEmail;
                    }
                }
                else
                {
                    // details.ToEmail = details.ToEmail;
                }
            }
            if (details.ToEmail != null && details.ToEmail != "")
            {
                if (details.HODmailid != null)
                {
                    if (details.HODmailid != "")
                    {
                        details.ToEmail = details.ToEmail + "," + details.HODmailid;
                        //details.ToEmail = details.ToEmail + "," + hremailid + "," + details.HODmailid;
                    }
                    else
                    {
                        //details.ToEmail = details.ToEmail;
                    }
                }
                else
                {
                    //details.ToEmail = details.ToEmail;
                }
            }
            else
            {
                if (details.HODmailid != null)
                {
                    if (details.HODmailid != "")
                    {
                        details.ToEmail = details.HODmailid;
                        //details.ToEmail = details.ToEmail + "," + hremailid + "," + details.HODmailid;
                    }
                    else
                    {
                        //details.ToEmail = details.ToEmail;
                    }
                }
                else
                {
                    //details.ToEmail = details.ToEmail;
                }
            }
            // details.CCEmail = hremailid;
            // details.CCEmail = Session["emailId"].ToString();
            details.Module       = "IPE";
            details.EmailSubject = "Incentive Point Adjustment";
            //details.Type = DropDownListPublicationEntry.SelectedValue;
            details.Id = txtReferenceId.Text;
            string FooterText = ConfigurationManager.AppSettings["FooterText"].ToString();
            string isStudent  = Session["IsStudent"].ToString();

            if (isStudent == "Y")
            {
                if (type == "S")
                {
                    details.MsgBody = "<span style=\"font-size: 10pt; color: #3300cc; font-family: Verdana\"><h4>Dear Sir/Madam,</h4> <br>" +
                                      "<p>For Certificate of Appreciation and encashment of research incentive points, request you to contact student research section of your institution/department along with the Bank detail form available in RMS Portal.</p>" + "<b>Incentive points with the rating  : " + txtTotalPoint.Text + "" + Session["Numbertype"].ToString() + "<br>" +
                                      "<br>" +
                                      "Author Name : " + Session["AuthorName"].ToString() + "<br>" +
                                      "Publication Id : " + txtReferenceId.Text + "<br>" +
                                      "Article Name :" + Session["Title"].ToString() + "<br>" + "<br>" + FooterText +
                                      " </b><br><b> </b></span>";
                }
                else
                {
                    details.MsgBody = "<span style=\"font-size: 10pt; color: #3300cc; font-family: Verdana\"><h4>Dear Sir/Madam,</h4> <br>" +
                                      //"<b> Incentive points with the rating '" + total.Text + "' added. <br> " +
                                      "<b>Incentive points with the rating  : " + txtTotalPoint.Text + " " + Session["Numbertype"].ToString() + "<br>" +
                                      "<br>" +
                                      "Author Name : " + Session["AuthorName"].ToString() + "<br>" +
                                      "Publication Id : " + txtReferenceId.Text + "<br>" +
                                      "Article Name :" + Session["Title"].ToString() + "<br>" + "<br>" + FooterText +
                                      " </b><br><b> </b></span>";
                }
            }

            else
            {
                if (type == "S")
                {
                    details.MsgBody = "<span style=\"font-size: 10pt; color: #3300cc; font-family: Verdana\"><h4>Dear Sir/Madam,</h4> <br>" +
                                      "<p>For encashment of research incentive points, request you to contact student research section of your institution/department along with the Bank detail form available in RMS Portal.</p>" + "<b>Incentive points with the rating  : " + txtTotalPoint.Text + " " + Session["Numbertype"].ToString() + "<br>" +
                                      //"<b> Incentive points with the rating '" + total.Text + "' added. <br> " +
                                      "<br>" +
                                      "Author Name : " + Session["AuthorName"].ToString() + "<br>" +
                                      "Publication Id : " + txtReferenceId.Text + "<br>" +
                                      "Article Name :" + Session["Title"].ToString() + "<br>" + "<br>" + FooterText +
                                      " </b><br><b> </b></span>";
                }
                else
                {
                    details.MsgBody = "<span style=\"font-size: 10pt; color: #3300cc; font-family: Verdana\"><h4>Dear Sir/Madam,</h4> <br>" +
                                      //"<b> Incentive points with the rating '" + total.Text + "' added. <br> " +
                                      "<b>Incentive points with the rating  : " + txtTotalPoint.Text + " " + Session["Numbertype"].ToString() + "<br>" +
                                      "<br>" +
                                      "Author Name : " + Session["AuthorName"].ToString() + "<br>" +
                                      "Publication Id : " + txtReferenceId.Text + "<br>" +
                                      "Article Name :" + Session["Title"].ToString() + "<br>" + "<br>" + FooterText +
                                      " </b><br><b> </b></span>";
                }
            }

            if (details.ToEmail != "" && details.ToEmail != null)
            {
                resultv = obj.InsertIntoEmailQueue(details);
            }
            IncentiveData     obj3 = new IncentiveData();
            IncentiveBusiness C    = new IncentiveBusiness();


            if (emailid == "")
            {
                string AuthorName1 = Session["AuthorName"].ToString();
                obj3 = C.CheckUniqueIdIncentive(txtReferenceId.Text, "JA", details);
                int data = C.updateEmailtrackerIncentive(txtReferenceId.Text, "JA", details, obj3, AuthorName1);
            }

            if (resultv == true)
            {
                string CloseWindow1 = "alert('Mail Sent successfully')";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "newWindow", CloseWindow1, true);
            }
            else
            {
                string CloseWindow1 = "alert('Problem while sending mail')";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "newWindow", CloseWindow1, true);
            }
        }


        catch (Exception ex)
        {
            string CloseWindow1 = "alert('Problem while sending mail')";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "newWindow", CloseWindow1, true);
            log.Error(ex.Message);
            log.Error(ex.StackTrace);
        }
    }