Plain text and html not getting along in net.mail.message

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Howdy all.

Am using visual web developer 2005 (vb), xp pro sp2.

In testing of the system.net.mail to send email from an aspx page where
I'm pulling the email contents from a textbox, find that if I mix plain
text with html formatted text and set the isBodyHTML = true that I get
a continuous line of plain text without carriage returns and proper
HTML. I've a checkbox that if checked sets the IsBodyHTML=true.

email result:
nothing came through last time becuase txtbody was not assigned to
mailmessage body Testing change that allows html if checkbox checked
for it. Keep the carriage return? So them will this format correctly?
If not, will I need to use bodyencoding ut8? Or what? Then also send as
body is html to see difference? Maybe add a checkbox to use html...
"Element 'Import' is missing the '>' character from its start tag"
Done! <-- Done was centered and bolded in the email test.


**************************************
But if I send it as isBodyHTTML=false then I get carriage returns and
html tages displayed:

email result:
will it fail

Testing change to code that body is NOT HTML.
So them will this format correctly?

If not, will I need to use bodyencoding ut8?

Or what?

Then also send as body is html to see difference?

Maybe add a checkbox to use html...


"Element 'Import' is missing the '>' character from its start tag"

<p align=center>
<em><strong>Done!</strong></em>
</p>

***************************************
What I'd like is to understand whether I can mix the two - plain text
w/carriage returns & HTML - or whether I can have either one or the
other and not both without using alternativeview which I haven't yet
used but don't think its useful as I'm pulling the text from a textbox.

Appreciate any suggestion/comments.

Thank you,
Rey

*********************************************
Below is code being used.
Dim MyMail As MailMessage = New MailMessage()
Dim SMTPMail As SmtpClient = New SmtpClient("abc.beammeup.com")
Dim x As Int16

' new system.net.mail format
MyMail.From = New MailAddress("ITHelpDesk@xxxxxxxxxxx")

' intent is to separate to addresses on ;
' count them and loop to add
Dim arAddresses() As String = Split(txtSendTo, ";")
Dim intArrSize As Int16 = arAddresses.Length

Try

If arAddresses.Length > 1 Then
For x = 0 To arAddresses.Length - 1
MyMail.To.Add(arAddresses(x))
Next
Else
MyMail.To.Add(txtSendTo)

End If

MyMail.Subject = txtSubject.Text

' depending on whether cboHTML checkbox is checked
If cboHTML.Checked = True Then
' use html...
MyMail.IsBodyHtml = True
Else
MyMail.IsBodyHtml = False
End If

MyMail.BodyEncoding = Encoding.UTF8

' protect from scripts
'MyMail.Body = HttpUtility.HtmlEncode(txtBody.Text)

MyMail.Body = txtBody.Text

SMTPMail.Send(MyMail)

Catch httpexc As HttpRequestValidationException
txtErr.Text = "Problem encountered while attempting to send
email." & ControlChars.CrLf & _
"Please notify IT Dept with reason listed below." &
ControlChars.CrLf & _
"Reason: " & httpexc.Message

txtErr.Visible = True

Catch exc As Exception
txtErr.Text = "Problem encountered while attempting to send
email." & ControlChars.CrLf & _
"Please notify IT Dept with reason listed below." &
ControlChars.CrLf & _
"Reason: " & exc.Message

txtErr.Visible = True
End Try

.



Relevant Pages

  • RE: SMTPMAIL Format & File Link??
    ... you need to include the <html> tags also. ... Dim newMail As New MailMessage ... > Dim stringMessage As String ...
    (microsoft.public.dotnet.languages.vb)
  • Re: multiple row updates in MYSQL using HTML
    ... > if the checkbox is checked incase you are updating most of the records ... >>all to another perl script to perform the update. ... >>I basically need maintenance of one table with unlimited rows containing ... HTML? ...
    (comp.lang.perl)
  • Re: Problem with Javascript in a UserControl
    ... Make a look at the HTML generated by your code and find your checkbox ID. ... fine if I put the UserControl Data directly in my Web Page. ... I am used to seeing this from DataGrids, but not as a regular control on the page. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: How to extract data from a checkbox & print it in MS Word
    ... This particular newsgroup really is dedicated to XML related conversations. ... Now you are asking how to extract data from some Web site, and that means extrarcting something from HTML. ... how to add or make some checkbox somewhere. ...
    (comp.text.xml)
  • RE: Adding CssClass property default to custom checkbox wraps with span tag
    ... checkBox server control,correct? ... doesn't 100% identical to the html checkbox input element. ... element inside the ASP.NET checkbox server control, ...
    (microsoft.public.dotnet.framework.aspnet.buildingcontrols)