How do I put multiple form parts in to the body section of an email (in V.B. asp.net 2.0 System.Net.

Discussion in 'ASP.NET 2.0' started by vvsharma, Dec 27, 2006.

  1. 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
     
  2. 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:p>


    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:p>
    <%@ Import Namespace="System.Net.Mail" %></o:p>
    </o:p>
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"></o:p>
    </o:p>
    <script runat="server"></o:p>
    </o:p>
    Protected Sub SendEmail_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SendEmail.Click

    </o:p>
    '!!! UPDATE THIS VALUE TO YOUR EMAIL ADDRESS</o:p>
    Const ToAddress As String = "[email protected]"</o:p>
    </o:p>
    '(1) Create the MailMessage instance</o:p>
    Dim mm As New MailMessage(UsersEmail.Text, ToAddress)</o:p>
    </o:p>
    '(2) Assign the MailMessage's properties-This is the code to specify and send the email body</o:p>
    mm.Subject = "Form Test"</o:p>
    mm.Body = Body.Text</o:p>
    mm.IsBodyHtml = True</o:p>
    </o:p>
    '(3) Create the SmtpClient object</o:p>
    Dim smtp As New SmtpClient</o:p>
    </o:p>
    '(4) Send the MailMessage (will use the Web.config settings)</o:p>
    smtp.Send(mm)</o:p>
    End Sub




    .....................
    .....................
    ....................


    Subject:</b>
    <asp:TextBox runat="server" ID="Subject" Columns="30"></asp:TextBox></td></o:p>



    Name:
    <asp:TextBox ID="Name" runat="server"></asp:TextBox>


    Country:
    <asp:TextBox ID="Country" runat="server"></asp:TextBox>


    </o:p>
    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
     
  3. 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
     
  4. Dont worry, I found a way my self




    sb.Append("" &amp; "More information: " &amp; 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
     
  5. I have this problem with texBox spacing not coming out in the email now
    I.E.:

    Form Code:
    [​IMG]



    FORM:

    [​IMG]





    Email from Form:



    [​IMG]



    Post Edited (vandiermen) : 12/28/2006 12:26:44 PM GMT
     
  6. or:

    Body.Text.Replace(System.Environment.NewLine, "")



    sb.Append("Cover Letter Body:" &amp; "" &amp; Body.Text.Replace(System.Environment.NewLine, "") &amp; "" &amp; "")The new formcomes out great http://www.budgetwebdesign.com.au/contact-us.aspx


    Post Edited (vandiermen) : 12/29/2006 6:24:00 AM GMT
     
  7. 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
     

Share This Page