Use a StringBuilder to concatenate different parts of the body. Something like : //In your SendEmail_Click function //<%@ Import Namespace='System.Text' %> System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append('DASP'); sb.Append('IS'); sb.Append(' THE'); sb.Append('BEST'); mm.Body = sb.ToString(); Vikram DiscountASP.NET www.DiscountASP.NET
Today I am making a form that get sent through email using System.Net.Mail (asp.net 2.0) and want to know how I would best send multiple form information in one body section on an email</o> All I have read is that you can ? use StringBuilder class. Append all parts to the message and pass it to mm.Body? SOUNDS GOOD, But I don?t know how, or what the code is or where to find the code I know it should be my job to find it my self, but I would love all the code to Append all parts to the message and pass it to mm.Body, Somehow add all the TextBox parts and other things in to one-thing andcall that the body, I would love to know how This is my code at the moment <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="CoverLetter.aspx.vb" Inherits="Contact" Title="My Super Resume: Starter----" %></o> <%@ Import Namespace="System.Net.Mail" %></o> </o> <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"></o> </o> <script runat="server"></o> </o> Protected Sub SendEmail_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SendEmail.Click </o> '!!! UPDATE THIS VALUE TO YOUR EMAIL ADDRESS</o> Const ToAddress As String = "[email protected]"</o> </o> '(1) Create the MailMessage instance</o> Dim mm As New MailMessage(UsersEmail.Text, ToAddress)</o> </o> '(2) Assign the MailMessage's properties-This is the code to specify and send the email body</o> mm.Subject = "Form Test"</o> mm.Body = Body.Text</o> mm.IsBodyHtml = True</o> </o> '(3) Create the SmtpClient object</o> Dim smtp As New SmtpClient</o> </o> '(4) Send the MailMessage (will use the Web.config settings)</o> smtp.Send(mm)</o> End Sub ..................... ..................... .................... Subject:</b> <asp:TextBox runat="server" ID="Subject" Columns="30"></asp:TextBox></td></o> Name: <asp:TextBox ID="Name" runat="server"></asp:TextBox> Country: <asp:TextBox ID="Country" runat="server"></asp:TextBox> </o> b>Body:</b> <asp:TextBox runat="server" ID="Body" TextMode="MultiLine" Columns="55" Rows="10"></asp:TextBox> and so on..... Post Edited (vandiermen) : 12/27/2006 11:53:35 AM GMT
DASP IS THE BEST ! - I got it to work Dim sb As StringBuilder = New StringBuilder() sb.Append(Body.Text) sb.Append(TextBox1.Text) mm.Body = sb.ToString() Excellent Now what I have to do is add something to separate the fields in the email because what I'm getting is: Online Form: Name: michael Body: 123 456 789 Email Body: michael123 456 789 Post Edited (vandiermen) : 12/28/2006 10:20:09 AM GMT
Dont worry, I found a way my self sb.Append("" & "More information: " & TextBox1.Text) and so on... I am so happy I am finally through it! Thanks oops its not over yet, I need to find a way to redirect the page, at the moment it is just posting back to its self This is the form I have been testing: http://www.budgetwebdesign.com.au/contact-us.aspx Post Edited (vandiermen) : 12/29/2006 6:20:26 AM GMT
I have this problem with texBox spacing not coming out in the email now I.E.: Form Code: FORM: Email from Form: Post Edited (vandiermen) : 12/28/2006 12:26:44 PM GMT
or: Body.Text.Replace(System.Environment.NewLine, "") sb.Append("Cover Letter Body:" & "" & Body.Text.Replace(System.Environment.NewLine, "") & "" & "")The new formcomes out great http://www.budgetwebdesign.com.au/contact-us.aspx Post Edited (vandiermen) : 12/29/2006 6:24:00 AM GMT
Since you have set 'IsBodyHtml' property to true,you will need to use HTML tags to format your body .Otherwise set it to false instead and you could send regular text to send exactly in a format within the Textbox. Vikram DiscountASP.NET www.DiscountASP.NET