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

Format email when using system.web.mail

I have an aspx form that a user submits information, which is recorded to a database.

I want to send an email confirming their info. I am using vb.net a system.web.mail. Sending a static email works fine, but I want to include session variables of what they submitted and format the email such as put the data into a table.

I am having trouble formatting the text to send the HTML email.

Here is what I am trying...
I start with        

Session("EmailMsg") = "<b>Thank You for your Order: </b> " & Session("MyOrder") & "<br/>"

Then for each row of inforation the user submits I am doing this...

Session("EmailMsg") = Session("emailmsg") & lblItem1.Text & "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" & lblDescp1.Text & "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" & txtQty1.Text & "<br/>"

I have tried things like with no success

Session("EmailMsg") = Session("emailmsg") & "<table><td> lblItem2.Text</td> & "" & <td>lblDescp2.Text</td> & "" & <td>txtQty2.Text</td> &</table><br/> "


Can someone help me with formatting this email.

Thank You.
0
Wildone63
Asked:
Wildone63
  • 2
1 Solution
 
brutaldevCommented:
I would start by using a StringBuilder. It will make it very clean to append additional text onto your email.
Secondly, I would suggest using String.Format (or AppendFormat of the StringBuilder class). You can use numbered placeholders for the areas you want to inject without making all the concatenations. This reads easier as well...
Eg:
Dim sb As New System.Text.StringBuilder()
sb.AppendFormat("<b>Thank You for your Order: </b> {0}<br/>", Session("MyOrder")
...
sb.Append("<table>")
sb.AppendFormat("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>", lblItem1.Text, lblDescp1.Text, txtQty1.Text)
sb.AppendFormat("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>", lblItem2.Text, lblDescp2.Text, txtQty2.Text)
...
sb.Append("</table>")
Dim emailText = sb.ToString();

Open in new window

Your table was missing TR tags (for rows).
0
 
brutaldevCommented:
Excuse the last line, that's my C# showing through :)
It should be:
Dim emailText As String = sb.ToString()

Open in new window

0
 
Wildone63Author Commented:
Perfect!

Thank You!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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