Click here to Skip to main content
14,358,929 members
Rate this:
Please Sign up or sign in to vote.
See more:
public void Mail(GridViewRow grid)
    {
        StringBuilder strEmail = new StringBuilder();
        //GridViewRow grid = GVEcDecision.Rows[0];
        GridView gvChild = (GridView)grid.FindControl("GVInspectorDetails");
        string StrInspector = string.Empty;
        Label lblInspector = null;
        string StrMobile = string.Empty;
        Label Mobile = null;
        if (gvChild != null)
        {

            foreach (GridViewRow row in gvChild.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    Label Lblcheck = (Label)row.FindControl("lblemail");
                    lblInspector = (Label)row.FindControl("LblName");
                    strEmail.Append("," + Lblcheck.Text);
                    string Inspectorname = Lblcheck.Text.ToString();
                    Mobile = (Label)row.FindControl("Mobile");

                    if (lblInspector != null)
                    {
                        StrInspector = lblInspector.Text;
                    }
                    if (Mobile != null)
                    {
                        StrMobile = Mobile.Text;

                    }
                    Label lblcollegename = (Label)grid.FindControl("lblcollegename");
                    Label lblinsptype = (Label)grid.FindControl("lblinsptype");
                    Label lblcoursespec = (Label)grid.FindControl("lblcoursespec");
                    string CollegeName = grid.Cells[4].Text;
                    string insptype = grid.Cells[5].Text;
                    string coursespec = grid.Cells[6].Text;
                    Label LblSubInspectionType = (Label)grid.FindControl("LblSubInspectionType");
                    Label lblfroseat = (Label)grid.FindControl("lblfroseat");
                    Label lblIncrSeat = (Label)grid.FindControl("lblIncrSeat");

                    string subinsptype = LblSubInspectionType.Text.ToString();
                    string FormSeat = lblfroseat.Text.ToString();
                    string toSeat = lblIncrSeat.Text.ToString();
                    TextBox txt1 = (TextBox)grid.FindControl("TxtEnddate");
                    string ToDate = txt1.Text.ToString();
                    TextBox txt2 = (TextBox)grid.FindControl("TxtStartdate");
                    string FormDate = txt2.Text.ToString();
                    Label lblstate = (Label)grid.FindControl("lblStatename");
                    string State = lblstate.Text.ToString();
                    Label lblcity = (Label)grid.FindControl("lblcity");
                    string city = lblcity.Text.ToString();

                    StringBuilder mailbody = new StringBuilder();
                    System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
                    string email = strEmail.ToString().Substring(1, strEmail.ToString().Length - 1);
                    string[] emailList = email.Split(',');
                    for (int j = 0; j <; emailList.Length; j++)
                   // foreach (string value in emailList)
                    {
                        
                        message.To.Add(new System.Net.Mail.MailAddress(emailList[j]));
                       
                      
                            message.Subject = "Appointment of Council's Inspectors";
                            message.Body = StrInspector + "," + city + "," + StrMobile + " <br> <br>This is Confirmation mail that You have been appointed for inspection as per Your "
                                                 + "availity after Telephonic Discussion.<br><br>" +
                                                 "Particulars for the inspection to be held as under:-<br>" +
                                                 " Course:-" + insptype + "<br>" +
                                                 " Purpose:-" + subinsptype + "<br>" +
                                                 " Seats:-" + toSeat + "<br>" +
                                                 " City:-" + city + "<br>" +
                                                 " State:-" + State + "<br>" +
                                                 " Date:-" + FormDate + "To" + ToDate + "<br> <br>" +
                                                 "You will get a Formal Letter from DCI including all details about the College to be inspected<br>" +
                                                 "before one day to inspection to be held through mail<br><br>" +
                                                 " The Dental Council of India has engaged M/s Balmer Lawrie & Co.Ltd., a Govt.of <br>" +
                                                 " India authorized travel partner to make bookings of air-tickets,hotel accommodation <br>" +
                                                 " and taxi for all the inspectors/Visitors of the Council while going on DCI inspection. <br>" +
                                                 " Therefore the said travel partner will contact you regarding your travel plan and will <br>" +
                                                 " make travel arrangements accordingly.in case of any query and clarification you may <br>" +
                                                 "contact the travel partner's representative Mr.Omprakash at 9899604205,011- <br>" +
                                                 "42524112 or E-mail:prakash.o@balmerlawrie.com & ridhi.s@vacationsexotica.com<br><br>" +
                                                 "<Now, you are requested to complete your preparation for the aforesaid inspection.in case<br>" +
                                                 "<of any query you may contact us: Contact No.011-23236544 & 9818189120 and E-mail us<br>" +
                                                 "<at:inspection@dciindia.org<br><br>" +
                                                 "Please acknowledge the receiving immediately by E-mail<br>" +
                                                 "reply on inspections@dciindia.org.<br><br><br>" +
                                                 "Thanking You<br><br>" +
                                                 "Secretary<br>" +
                                                 "Dental Council of India<br>" +
                                                 "New Delhi<br><br>" +
                                                 "Copy to:<br>" +
                                                 "Mr.Omprakash and Ms.Ridhi,M/s.Balmer Lawrie & Co.Ltd.for furtherance in the<br>" +
                                                 "matter.";
                        }

                        message.IsBodyHtml = true;
                        MailAddress fromAddress = new MailAddress("inspections@dciindia.org", "DCI");
                        message.From = fromAddress;
                        //added New
                        MailAddress copy = new MailAddress("inspections@dciindia.org");
                        message.CC.Add(copy);
                        //MailAddress copy1 = new MailAddress("prakash.o@balmerlawrie.com");
                        //message.CC.Add(copy1);
                        //MailAddress copy2 = new MailAddress("ridhi.s@vacationsexotica.com");
                        //message.CC.Add(copy2);
                        //End
                        SmtpClient smtp = new SmtpClient();
                        smtp.Host = "mail.dciindia.org";
                        //smtp.EnableSsl = true;
                        NetworkCredential credential = new NetworkCredential("inspections@dciindia.org", "getin@inspdci!1015");
                        smtp.Credentials = credential;
                        smtp.Port = 26;
                        smtp.Send(message);
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Mail has been Successfully send')", true);
                    }
                }
            }
        }


What I have tried:

above is my code and it is working fine -
i want to know i get two index [0],[1] in emaillist so what i do only get value of [1] index so please help me
Posted
Updated 23-May-17 9:36am
v8
Comments
[no name] 23-May-17 8:12am
   
"i want to know what i do when it s get two email in emailList then mail send code run", you learn how to ask questions that make sense. Your statement doesn't make any sense.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

What you appear to be trying to do is to prevent duplicate emails going out - if an email has been sent to an address before, stop it going this time.

The problem is that that means you storing information on "sent / not-sent" status somewhere - and the logical place to do that it with the data in your GridView, as it's the only place that you can really look at, other than the Session. I'd suggest that what you need to do is update the source of your Gridview data - presumably it's a DB of some kind - to include an "emailed" column which you then update when you sent the mail.
Otherwise, if the user opens a new page with the same data the emails will be sent again.

So start by looking at your datasource, and where it comes from - you need to have some system implemented there to prevent this as well as checks added to the code you show. And we can't see any of that, so we can't give you precise instructions!
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100