Question about Email body in my asp.net
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????
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 : " & txtComment.Text + "<br>"
msgFax.Body = strBody
SmtpMail.SmtpServer = "server.companyname.com"
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...
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.
If checkbox1.checked Then
strBody += " * #1 is Checked "
If checkbox2.checked Then
strBody += " * #2 is Checked "
Hope this helps to answer your questions.
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center