Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to format textbox data into an email message [modified]

How to format textbox data into an email message [modified]

Scheduled Pinned Locked Moved ASP.NET
helptutorialcsharpcom
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    archangel717
    wrote on last edited by
    #1

    Hey all, I have searched all over the internet for this, but haven't found exactly what I am looking for. I am not an expert VB.Net programmer, so bear with me here. I have about 12 text and drop down boxes that will reside on a 'Customer Account Creation Request' form page. An HR rep will fill out the form with the appropriate fields and then click submit. It will then just email IT the contents of the form. My code works and all is well. My only problem is to actually format the email so it isn't just one long line of information. I am half way there, but I can't figure out how to insert the appropriate breaks and formatting. This is probably so simple, but I've never done it before in this manner so I need help! A sample of my code is below: Dim Email As New System.Net.Mail.MailMessage( _ "email@email.com", "email@email.com") Email.IsBodyHtml = True Email.Subject = "New Account Creation Request" Email.Body = "A new account was requested by " & txtRequesterFirst.Text & " " & txtRequesterLast.Text & " on " & DateTime.Now.ToString() & ". Employee Name - " & txtFirst.Text & " " & txtMiddle.Text & " " & txtLast.Text The email.body line is just on one line, so thats why it might display weird in this post. Could someone point me in the right direction? I basically want each text box to be on its own line in the generated email. For example, the Employee Name part should be on the next line of the email and not alongside the first part of the message. Thanks!! -- modified at 12:56 Friday 11th May, 2007

    F 1 Reply Last reply
    0
    • A archangel717

      Hey all, I have searched all over the internet for this, but haven't found exactly what I am looking for. I am not an expert VB.Net programmer, so bear with me here. I have about 12 text and drop down boxes that will reside on a 'Customer Account Creation Request' form page. An HR rep will fill out the form with the appropriate fields and then click submit. It will then just email IT the contents of the form. My code works and all is well. My only problem is to actually format the email so it isn't just one long line of information. I am half way there, but I can't figure out how to insert the appropriate breaks and formatting. This is probably so simple, but I've never done it before in this manner so I need help! A sample of my code is below: Dim Email As New System.Net.Mail.MailMessage( _ "email@email.com", "email@email.com") Email.IsBodyHtml = True Email.Subject = "New Account Creation Request" Email.Body = "A new account was requested by " & txtRequesterFirst.Text & " " & txtRequesterLast.Text & " on " & DateTime.Now.ToString() & ". Employee Name - " & txtFirst.Text & " " & txtMiddle.Text & " " & txtLast.Text The email.body line is just on one line, so thats why it might display weird in this post. Could someone point me in the right direction? I basically want each text box to be on its own line in the generated email. For example, the Employee Name part should be on the next line of the email and not alongside the first part of the message. Thanks!! -- modified at 12:56 Friday 11th May, 2007

      F Offline
      F Offline
      Fred_Smith
      wrote on last edited by
      #2

      You have: Email.IsBodyHtml = True So simply insert html
      tags where you want them, eg: Email.Body = "A new account was requested by " & txtRequesterFirst.Text & " " & txtRequesterLast.Text & " on " & DateTime.Now.ToString() & ".
      Employee Name - " & txtFirst.Text & " " & txtMiddle.Text & " " & txtLast.Text You can add any html you want:- bold, font color etc. If you want plain text instead set Email.IsBodyHtml = False amd insert newlines instead, viz: Email.Body = "A new account was requested by " & txtRequesterFirst.Text & " " & txtRequesterLast.Text & " on " & DateTime.Now.ToString() & "." & vbCrLf & "Employee Name - " & txtFirst.Text & " " & txtMiddle.Text & " " & txtLast.Text cheers Fred

      A 1 Reply Last reply
      0
      • F Fred_Smith

        You have: Email.IsBodyHtml = True So simply insert html
        tags where you want them, eg: Email.Body = "A new account was requested by " & txtRequesterFirst.Text & " " & txtRequesterLast.Text & " on " & DateTime.Now.ToString() & ".
        Employee Name - " & txtFirst.Text & " " & txtMiddle.Text & " " & txtLast.Text You can add any html you want:- bold, font color etc. If you want plain text instead set Email.IsBodyHtml = False amd insert newlines instead, viz: Email.Body = "A new account was requested by " & txtRequesterFirst.Text & " " & txtRequesterLast.Text & " on " & DateTime.Now.ToString() & "." & vbCrLf & "Employee Name - " & txtFirst.Text & " " & txtMiddle.Text & " " & txtLast.Text cheers Fred

        A Offline
        A Offline
        archangel717
        wrote on last edited by
        #3

        Wow that makes me feel inadequate in my coding experience! Haha. Thanks for the quick fix. I could have sworn that I tried inserting HTML tags in my code, but I guess I didn't try it enough. Thanks Fred!

        A 1 Reply Last reply
        0
        • A archangel717

          Wow that makes me feel inadequate in my coding experience! Haha. Thanks for the quick fix. I could have sworn that I tried inserting HTML tags in my code, but I guess I didn't try it enough. Thanks Fred!

          A Offline
          A Offline
          archangel717
          wrote on last edited by
          #4

          The only other piece that I would like to add would be the ability for the user to enter their email address in a text box and have the app use that email address to send the email. My code is: Email.From.Equals(txtEmail.Text) This seems to be correct syntax, but .net is just using whatever is set as the credentials in the web.config file. If I remove all credentials and try the anonymous route, would this line of code work? I wanted to get feedback before going on a wild goose chase. Thanks again!

          I 1 Reply Last reply
          0
          • A archangel717

            The only other piece that I would like to add would be the ability for the user to enter their email address in a text box and have the app use that email address to send the email. My code is: Email.From.Equals(txtEmail.Text) This seems to be correct syntax, but .net is just using whatever is set as the credentials in the web.config file. If I remove all credentials and try the anonymous route, would this line of code work? I wanted to get feedback before going on a wild goose chase. Thanks again!

            I Offline
            I Offline
            Ibuprofen
            wrote on last edited by
            #5

            Not sure, what the vb code is, but here it is in C#. private void SendEmail() { try { MailMessage newMail = new MailMessage(); newMail.From=Email.Text; newMail.To="email@email.com"; newMail.Cc="email@email.com;email2@email.com"; newMail.Subject="User Feedback"; newMail.Body=SubmitBy.Text+" filled out a Web User Feedback Support form.\r\n\r\n"+SubmitBy.Text + " wrote:\r\n"+Comments.Text; SmtpMail.SmtpServer="000.000.000.000"; SmtpMail.Send(newMail); } catch(Exception err) { string s = err.Message; } }

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups