• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 439
  • Last Modified:

Insert Dynamic table in HTML Email ASP.NET

I have the following email that I would like to include a bullet list or table with items that the recipient need to complete.   I won't know how many items per email until the SP is run.  How do I do that?  Thank you.

Private Sub RevisionEmail()
        Dim cnn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("myprovalConnectionString").ConnectionString)
        Try
            Dim cmd As New System.Data.SqlClient.SqlCommand
            cmd.Connection = cnn
            cmd.CommandType = Data.CommandType.StoredProcedure
            cmd.CommandText = "dbo.GetOrderRevitionDetails_Email"
            cmd.Parameters.Add("@OrdersProductKey", Data.SqlDbType.Int).Value = Session("OrdersProductKey")
            cnn.Open()
            Dim dt As New System.Data.DataTable

            Dim dr As System.Data.SqlClient.SqlDataReader = cmd.ExecuteReader

            dr.Read()

            If dr.HasRows Then
                Const ToAddress As String = "provaltesting@tcvaluations.com"
                '(1) Create the MailMessage instance
                Dim mm As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()
                '(2) Assign the MailMessage's properties
                mm.To.Add(New System.Net.Mail.MailAddress(ToAddress))
                mm.From = New System.Net.Mail.MailAddress(System.Configuration.ConfigurationManager.AppSettings("FromEmailAddress"))
                mm.Subject = "*** Please address QC Request(s) ASAP *** <%Address%>"
                mm.Body = "<table style='width:100%;'><tr><td>" +
                      "Hi <%Name%>,<br /><br />" +
                    " Please return to our web site, address the following QC requests and resubmit this report by XXXXX Pacific Time XX/XX/XX.  Thank you!  <br />" +
                   " Since this is an exterior only assignment, you will be free to schedule the inspection for a day and time that is most convenient for you (providing the due date and time will be honored).<br />" +
                    "</td> </tr>" +
                 "<tr style='background-color: #006699'><td style='color: #FFFFFF; font-weight: bold; font-size: medium valign='bottom'>Order Details</td></tr>" +
                " <tr>" +
                    " <td class='style4' >" +
                        " <table>" +
                        "     <tr>" +
                           "    <td>Order Id:&nbsp; </td><td><%OPK%></td>" +
                          "     </tr>" +
                            "   <tr>" +
                            "   <td>Property Address: </td><td><%Address%></td>" +
                               "  </tr>" +
                                "   <tr>" +
                            "   <td>Property City: </td><td><%City%></td>" +
                               "  </tr>" +
                                "   <tr>" +
                            "   <td>Property State: </td><td><%State%></td>" +
                               "  </tr>" +
                                "   <tr>" +
                            "   <td>Property Zip: </td><td><%Zip%></td>" +
                               "  </tr>" +
                               "  <tr>" +
                               "  <td>Due By:&nbsp;</td><td><%DueDay%> - <%DueDate%> <%DueTime%></td></tr>" +
                               "    <tr>" +
                                "   <td>Form Type: </td><td><%Report%></td>" +
                                "   </tr>" +
                               "    <tr>" +
                                 "  <td>Fee:&nbsp;</td><td><%Fee%></td></tr>" +
                                "   </table> </td></tr> " +
                              "  <tr style='background-color: #006699'>" +
                    "   <td style='color: #FFFFFF; font-weight: bold; font-size: medium' valign='bottom'>Special Instructions</td></tr>" +
                   "<tr><td class='style4'> <table><tr> <td><%Special%></td><td><label id='Label1'></label>" +
     "</td>  </tr> </table> </td></tr> <tr> <td class='style2'>" +
                " To accept this order <a href='http://www.myproval.com/VendorPages/VendorAcceptBroadcast.aspx?OPK=<%OPK%>&OVK=<%OVK%>'  style='color:#0000FF; text-decoration:underline;' target='_blank'>Click here.</a><br />" +
                 "  To decline this order&nbsp;<a href='http://www.myproval.com/VendorPages/VendorDeclineBroadcast.aspx?OPK=<%OPK%>&OVK=<%OVK%>' style='color:#0000FF; text-decoration:underline;' target='_blank'>Click here.</a>" +
                "   <br />" +
                 "  <br />" +
                "   <br />" +
                 "  NEED HELP?<br />" +
                 "  If you have any questions, please contact our team:<br />" +
                                 "  Thank you for your service!<br />" +
                 "  </tr>  </table>" +
                 "   <br />" +
                 "   <br />" +
                 "   <br />" +
                 "   <br />" +
                 "   <br />" +
                 " <p style='font-size: 9px; font-weight: normal; text-transform: uppercase; color: #000000'>FormID: MA-Ext</p>"
                mm.IsBodyHtml = True
                mm.Body = mm.Body.Replace("<%OPK%>", dr("OrdersProductKey"))
                mm.Body = mm.Body.Replace("<%Name%>", dr("VendorFirstName"))
                mm.Body = mm.Body.Replace("<%Address%>", dr("Address"))
                mm.Body = mm.Body.Replace("<%DueDay%>", dr("DueDay"))
                mm.Body = mm.Body.Replace("<%DueDate%>", dr("VendorDueDate"))
                mm.Body = mm.Body.Replace("<%Report%>", dr("ReportTypeName"))
                mm.Body = mm.Body.Replace("<%City%>", dr("City"))
                mm.Body = mm.Body.Replace("<%State%>", dr("StateAbbr"))
                mm.Body = mm.Body.Replace("<%Zip%>", dr("Zip"))
                dr.Close()


                '(3) Create the SmtpClient object
                Dim smtp As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient()

                '(4) Send the MailMessage (will use the Web.config settings)
                smtp.Send(mm)
            End If
        Finally
            cnn.Close()
        End Try
    End Sub

Open in new window

0
rcowen00
Asked:
rcowen00
1 Solution
 
Alan WarrenCommented:
Hi rcowen00,

You can use While reader.read to loop through the records/rows in the datareader.
Create your open and close UL tags outside of the reader.read and populate the LI tags and content inside the reader.read loop.

Dim strUnorderedList As String = "<ul>"
While reader.Read
  strUnorderedList += "<li>" + Trim(reader("item_description").ToString()) + "</li>"
End While
strUnorderedList += "</ul>"

Open in new window

Alan ";0)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now