Question about Email body in my asp.net


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Question about Email body in my asp.net

  1. #1
    Join Date
    Dec 2004
    Location
    Chicago, IL
    Posts
    11

    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.Subject = "PRIMARY SCHOOL APPLICATION"
    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"
    SmtpMail.Send(msgFax)

  2. #2
    Join Date
    Nov 2003
    Location
    Austin, Texas
    Posts
    59
    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...

    Code:
    <HTML>
    .
    .
    .
    <Table>
         <tr>
            <td><<PutHeadingHere>></td>
         </tr>
    </Table>
    .
    .
    .
    </HTML>
    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...

    Code:
    If checkbox1.checked Then
       strBody += " * #1 is Checked "
    EndIf
    
    If checkbox2.checked Then
       strBody += " * #2 is Checked "
    EndIf
    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
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

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