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

Discussion in 'ASP .Net' started by Rey, Nov 13, 2006.

  1. Rey

    Rey Guest

    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("")

    ' 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
    Rey, Nov 13, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Sutter
    Replies:
    0
    Views:
    628
    John Sutter
    Jan 13, 2004
  2. Joergen Bech
    Replies:
    0
    Views:
    533
    Joergen Bech
    Jul 27, 2005
  3. sgane
    Replies:
    1
    Views:
    682
    Paul Lutus
    Oct 11, 2004
  4. Elton Pruitt
    Replies:
    2
    Views:
    5,790
    akjoshi
    Jun 12, 2006
  5. Jake Barnes
    Replies:
    9
    Views:
    752
    dave cutts
    Feb 21, 2006
Loading...

Share This Page