Пример #1
0
    protected void btnSend_Click(object sender, EventArgs e)
    {
        try
        {
            foreach (GridViewRow gvr in grdESubInfo.Rows)
            {
                CheckBox chkIssue = (CheckBox)gvr.FindControl("chkIssue");
                HiddenField hdnPreferenceID = (HiddenField)gvr.FindControl("hdnPreferenceID");
                if (chkIssue.Checked == true)
                {
                    DataSet dsgetDataByPreferenceID = objESubscriptionBL.GetDataByPreferenceID(hdnPreferenceID.Value);
                    if (dsgetDataByPreferenceID.Tables[0].Rows.Count > 0)
                    {
                        for (int i = 0; i < dsgetDataByPreferenceID.Tables[0].Rows.Count; i++)
                        {
                            if (dsgetDataByPreferenceID.Tables[0].Rows[i]["Makeid"].ToString() != "0")
                            {
                                string EName = dsgetDataByPreferenceID.Tables[0].Rows[i]["Name"].ToString();
                                string EMake = dsgetDataByPreferenceID.Tables[0].Rows[i]["make"].ToString();
                                string EModel = dsgetDataByPreferenceID.Tables[0].Rows[i]["model"].ToString();
                                string EPrice = dsgetDataByPreferenceID.Tables[0].Rows[i]["PriceRange"].ToString();
                                DataSet dsPrefercars = objESubscriptionBL.GetCarSubscription_Ads(dsgetDataByPreferenceID.Tables[0].Rows[i]["Makeid"].ToString(), dsgetDataByPreferenceID.Tables[0].Rows[i]["ModelID"].ToString(), dsgetDataByPreferenceID.Tables[0].Rows[i]["PriceRange"].ToString());
                                DataTable dtPreferTable = dsPrefercars.Tables[0];
                                clsMailFormats format = new clsMailFormats();
                                MailMessage msg = new MailMessage();
                                msg.From = new MailAddress("*****@*****.**");
                                msg.To.Add(dsgetDataByPreferenceID.Tables[0].Rows[i]["Email"].ToString());
                                //msg.To.Add("*****@*****.**");
                                msg.Subject = "10 Used cars " + EMake.ToString() + " " + EModel.ToString();
                                msg.IsBodyHtml = true;
                                string text = string.Empty;
                                text = format.SendSubscriptionMail(ref text, dtPreferTable, EName, EMake, EModel, EPrice);
                                msg.Body = text.ToString();
                                SmtpClient smtp = new SmtpClient();
                                //smtp.Host = "smtp.gmail.com";
                                //smtp.Port = 587;
                                //smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "hugomirad");
                                //smtp.EnableSsl = true;
                                //smtp.Send(msg);
                                smtp.Host = "127.0.0.1";
                                smtp.Port = 25;
                                smtp.Send(msg);
                            }
                        }
                    }
                }
                mpealteruser.Show();
                lblErr.Visible = true;
                lblErr.Text = "Email(s) successfully send";
            }

        }
        catch (Exception ex)
        {
        }
    }