DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2004
    Chicago, IL

    Question about Email body in my asp.net

    Hi experts,

    My asp.net application will send an email to our marketing department when a user filled out the application.
    In my strBody of the following code, it will list all 6 strCheckBoxs (string value) from my application. If
    However, how to write the lines that only when strCheckBoxs is not an empty string? I mean, skip the line if the strCheckBox is an empty string ""???

    Can I use IF--ELSE statement somewhere in this code to eliminate the rows which contains empty string strCheckBox????

    Thank you.

    Dim msgFax As MailMessage = New MailMessage
    msgFax.To = "name@domain"
    msgFax.From = "webmaster@domain"
    msgFax.BodyFormat = MailFormat.Html

    Dim strBody As String
    strBody = "<h3>BK and PRIMARY SCHOOL </h3>" + "<br>" + _
    " __________________________________________________________" + "<br>" + _
    "- CERTIFICATE OF ACHIEVEMENT - " + "<br>" + _
    " * " & strCheckBox1 + "<br>" + _
    " * " & strCheckBox2 + "<br>" + _
    " * " & strCheckBox3 + "<br>" + _
    " * " & strCheckBox4 + "<br>" + _
    " * " & strCheckBox5 + "<br>" + _
    " * " & strCheckBox6 + "<br>" + _
    " * Comments : &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" & txtComment.Text + "<br>"

    msgFax.Body = strBody
    SmtpMail.SmtpServer = "server.companyname.com"

  2. #2
    Join Date
    Nov 2003
    Austin, Texas
    Your question seems simple in nature. That may be because I am misunderstanding what your asking. First thing, do you understand what is going on here as far as how to build an HTML document to send as an email? If so, you should understand that all you are doing is construction a string that contains the HTML document. You can do pretty much anything that you need to build the string, such as IF/ELSE statements, or really anything else that you might need to build the HTML document as a string. In the end, as long as the string contains valid HTML, you should not have any problems.

    What I typically do when I am building an HTML document to be emailed, is that I first build a standalone HTML page. I then take the source of this page and create find/replace tokens. Maybe something like...

    Then I write logic to load the HTML template and find and replace what I need. This allows me to keep from having to build all of the HTML document using string in my code.

    Anyway, since you are building it directly on the code, keep in mind that it is just a string and you can do whatever string manipulation that you wish.

    So you could write code like...

    If checkbox1.checked Then
       strBody += " * #1 is Checked "
    If checkbox2.checked Then
       strBody += " * #2 is Checked "
    To get a little more advanced, you can use the forms collection and simply spin through it to get the values of all of the objects on the ASPX page that have been filled. If the checkbox was checked, it will be in the collection. If not, it will not be in the collection. I tend to lean on the forms collection because I can write a FOR EACH loop and spin through them all, and not have to write the 3 lines of code above for each item on the page.

    Hope this helps to answer your questions.

    Best regards,
    Greg Rothlander

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.