C# 告诉我们问题出在哪里。在调试中运行它。它进入for循环了吗?“呼叫sendmail不工作”是什么意思?它进入方法中了吗?它是否进入调用该方法的if块?感谢您的帮助,但我仍然遇到相同的问题。请让我确切地知道您得到错误的行,以便易于识别。 Employees

C# 告诉我们问题出在哪里。在调试中运行它。它进入for循环了吗?“呼叫sendmail不工作”是什么意思?它进入方法中了吗?它是否进入调用该方法的if块?感谢您的帮助,但我仍然遇到相同的问题。请让我确切地知道您得到错误的行,以便易于识别。 Employees ,c#,asp.net,sql-server-2008-r2,sendmail,C#,Asp.net,Sql Server 2008 R2,Sendmail,告诉我们问题出在哪里。在调试中运行它。它进入for循环了吗?“呼叫sendmail不工作”是什么意思?它进入方法中了吗?它是否进入调用该方法的if块?感谢您的帮助,但我仍然遇到相同的问题。请让我确切地知道您得到错误的行,以便易于识别。 Employees Table: NetID, Name Events Table: ID, Title BookingDetails Table: BookingID, EventID, NetID <asp:GridView ID="ListOfAva


告诉我们问题出在哪里。在调试中运行它。它进入for循环了吗?“呼叫
sendmail
不工作”是什么意思?它进入方法中了吗?它是否进入调用该方法的if块?感谢您的帮助,但我仍然遇到相同的问题。请让我确切地知道您得到错误的行,以便易于识别。
Employees Table: NetID, Name
Events Table: ID, Title
BookingDetails Table: BookingID, EventID, NetID
<asp:GridView ID="ListOfAvailableEvents_GrivView" runat="server" 
            AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333"
                    GridLines="None" AllowPaging="True">
                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" CssClass="generaltext" />
                    <Columns>
                        <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                        <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
                        <asp:BoundField DataField="Location" HeaderText="Location" SortExpression="Location" />
                        <asp:BoundField DataField="StartDateTime" HeaderText="Start Date & Time" SortExpression="StartDateTime" />
                        <asp:BoundField DataField="EndDateTime" HeaderText="End Date & Time" SortExpression="EndDateTime" />
                        <asp:BoundField DataField="NumberOfSeats" HeaderText="Number of Seats" SortExpression="NumberOfSeats" />
                        <asp:BoundField DataField="Number of Bookings" HeaderText="Number of Bookings" ReadOnly="True"
                            SortExpression="Number of Bookings" />
                        <asp:TemplateField HeaderText="">
                            <ItemTemplate>
                                <asp:Button ID="sendButton" runat="server" CssClass="button" Text="Send Reminder &rarr;"
                                    OnClick="btnSend_Click" />
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                    <HeaderStyle Font-Bold="True" CssClass="complete" />
                    <EditRowStyle BackColor="#999999" />
                    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                </asp:GridView>

                <asp:HiddenField ID="HiddenField1" runat="server" />

                <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:PM_RegistrationSysDBConnectionString %>"

            SelectCommand="SELECT Events.Title, Events.Description, Events.Location, Events.StartDateTime, Events.EndDateTime, Events.NumberOfSeats, COUNT(BookingDetails.BookingID) AS [Number of Bookings] FROM Events INNER JOIN BookingDetails ON Events.ID = BookingDetails.EventID WHERE (Events.IsActive = 1) GROUP BY Events.Title, Events.Description, Events.Location, Events.StartDateTime, Events.EndDateTime, Events.NumberOfSeats ORDER BY Events.StartDateTime DESC"></asp:SqlDataSource>
protected void btnSend_Click(object sender, EventArgs e)
    {
        GridViewRow gvrow = (GridViewRow)(((Button)sender)).NamingContainer;
        HiddenField1.Value = ListOfAvailableEvents_GrivView.DataKeys[gvrow.RowIndex].Value.ToString();

        string title = gvrow.Cells[0].Text;
        string description = gvrow.Cells[1].Text;
        string location = gvrow.Cells[2].Text;
        string startDateTime = gvrow.Cells[3].Text;
        string endDateTime = gvrow.Cells[4].Text;

        string connString = ".............................;";

        using (SqlConnection conn = new SqlConnection(connString))
        {
            var sbEmailAddresses = new System.Text.StringBuilder(2000);
            int eventID = Convert.ToInt32(HiddenField1.Value);

            //Open DB connection
            conn.Open();

            string cmdText = @"SELECT     dbo.Events.Title, dbo.Employees.NetID
                                FROM         dbo.BookingDetails INNER JOIN
                                        dbo.Events ON dbo.BookingDetails.EventID = @EventID INNER JOIN
                                        dbo.Employees ON dbo.BookingDetails.NetID = dbo.Employees.NetID";
            using (SqlCommand cmd = new SqlCommand(cmdText, conn)) 
            {
                cmd.Parameters.AddWithValue("@EventID", eventID);
                cmd.ExecuteNonQuery();

                SqlDataReader reader = cmd.ExecuteReader();
                if (reader != null)
                {
                    while (reader.Read())
                    {
                        var sName = reader.GetString(0);
                        if (!string.IsNullOrEmpty(sName))
                        {
                            if (sbEmailAddresses.Length != 0)
                            {
                                sbEmailAddresses.Append(", ");
                            }
                            sbEmailAddresses.Append(sName).Append("@appServer.com");
                        }
                    }
                }
                reader.Close();

                var sEMailAddresses = sbEmailAddresses.ToString();
                string body = "..........................";


                int sendCount = 0;
                List<string> addressList = new List<string>(sEMailAddresses.Split(','));
                StringBuilder addressesToSend = new StringBuilder();

                for (int userIndex = 0; userIndex < addressList.Count; userIndex++)
                {
                    sendCount++;
                    if (addressesToSend.Length > 0)
                        addressesToSend.Append(",");

                    addressesToSend.Append(addressList[userIndex]);
                    if (sendCount == 10 || userIndex == addressList.Count - 1)
                    {
                        SendEmail(addressesToSend.ToString(), "", "Registration REMINDER Notification", body, true);
                        addressesToSend.Clear();
                        sendCount = 0;
                    }
                }

                cmd.ExecuteNonQuery();
            }
            //reset the value of hiddenfield
            HiddenField1.Value = "-1";
        }
    }

    protected void SendEmail(string toAddresses, string fromAddress, string MailSubject, string MessageBody, bool isBodyHtml)
    {
        SmtpClient sc = new SmtpClient("MAIL ADDRESS");
        try
        {
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress("app@appServer.com", "Registration System");

            // In case the mail system doesn't like no to recipients. This could be removed
            //msg.To.Add("app@appServer.com");

            msg.Bcc.Add(toAddresses);
            msg.Subject = MailSubject;
            msg.Body = MessageBody;
            msg.IsBodyHtml = isBodyHtml;
            sc.Send(msg);
        }
        catch (Exception ex)
        {
            throw ex;
            // something bad happened
            //Response.Write("Something bad happened!");

        }

    }
for (int userIndex = 0; userIndex < addressList.Count-1; userIndex++)
                {