Beispiel #1
0
    private void SendMailFunction(string senderMailId, string password, int port, string sendTo, string who)
    {
        try
        {
            if (String.IsNullOrEmpty(sendTo))
            {
                return;
            }
            grdsendCustomerGaugeStatus.DataSource = null;
            grdsendCustomerGaugeStatus.DataBind();
            string sendQuery = null;
            if (who == "EMP")
            {
                sendQuery = @"Select cs.calibration_schedule_id, cs.gauge_id, gm.gauge_sr_no, gm.gauge_name, cs.next_due_date from calibration_schedule_TB as cs
                Left Outer Join gaugeMaster_TB as gm ON cs.gauge_id=gm.gauge_id
                where cs.status=1 and cs.customer_id=" + Convert.ToInt32(Session["Customer_ID"]) + " and cs.created_by_id=" + Convert.ToInt32(Session["User_ID"]) + " and cs.next_due_date <= (now()+15)";
                DataTable getnextDueStatus = g.ReturnData(sendQuery);
                grdsendCustomerGaugeStatus.DataSource = getnextDueStatus;
                grdsendCustomerGaugeStatus.DataBind();
            }
            else
            {
                try
                {
                    string  stprocedure = "spDashBoardQuery";
                    DataSet ds          = q.ProcdureWithTwoParam(stprocedure, 1, Convert.ToInt32(Session["Customer_ID"]));

                    grdsendCustomerGaugeStatus.DataSource = ds.Tables[0];
                    grdsendCustomerGaugeStatus.DataBind();
                }
                catch (Exception ex)
                {
                    Logger.Error(ex.Message);
                    //g.ShowMessage(this.Page, ex.Message);
                }
            }
            string[] strarryEmailId = sendTo.Split(',');
            string[] strsmtpget     = senderMailId.Split('@');
            string   a = strsmtpget[1].ToString();
            string   b = "smtp.";
            b = b + a;
            for (int i = 0; i < strarryEmailId.Count(); i++)
            {
                MailMessage objMail = new MailMessage();
                //string str1 = "*****@*****.**";
                string strSendTo = strarryEmailId[i].ToString();
                System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
                mail.To.Add(strSendTo);
                mail.From       = new MailAddress(senderMailId);
                mail.Subject    = "Gauge Due Status";
                mail.Body       = "<br><br>Hi Dear ..!!<br><br><br> ";
                mail.Body      += "Your gauge next due status date as below list:";
                mail.Body      += GetGridviewData(grdsendCustomerGaugeStatus);
                mail.Body      += "<br><br><br><b>Gauge Management System!!</b><br><br><br>";
                mail.IsBodyHtml = true;
                SmtpClient smtp = new SmtpClient();
                smtp.UseDefaultCredentials = false;
                smtp.Host        = b;// "smtp.gmail.com";
                smtp.Credentials = new System.Net.NetworkCredential(senderMailId, password);
                smtp.EnableSsl   = true;
                smtp.Port        = port;
                smtp.Send(mail);
            }
            DateTime date = new DateTime();
            date = DateTime.Now;
            string strDate = date.ToString("yyyy-MM-dd H:mm:ss");

            DataTable dtsavemailhist = g.ReturnData("Insert into sendMailHistoryTB (customer_id,user_id,send_Date) values(" + Convert.ToInt32(Session["Customer_ID"]) + "," + Convert.ToInt32(Session["User_ID"]) + ",'" + strDate + "')");
            //using (TTMSDataClassesDataContext ds = new TTMSDataClassesDataContext())
            // {
            //     sendMailHistoryTB sm = new sendMailHistoryTB();
            //     sm.customer_id = Convert.ToInt32(Session["Customer_ID"]);
            //     sm.user_id = Convert.ToInt32(Session["User_ID"]);
            //     sm.send_Date = DateTime.Now;
            //     ds.sendMailHistoryTBs.InsertOnSubmit(sm);
            //     ds.SubmitChanges();
            // }
        }
        catch (Exception ex)
        {
            Logger.Error(ex.Message);
            // g.ShowMessage(this.Page, ex.Message);
        }
    }