locked
why the receipients received plain text? (email) RRS feed

  • Question

  • i made a email program that sends... so i added some spice i put some color, font size, styles and etc...and i also set .isbodyHtml = true but still the receipients receive plain text pls help

     

     

     

     

    regards

    Monday, August 6, 2007 1:52 AM

Answers

  •  

    You’ve asked a question which has some complexity to it and it requires some expertise. I hope I can best show you in code:

     

    ‘Class member variables

     

    Protected Friend WithEvents doc As New mshtml.HTMLDocument ‘ Will require a  
                                                                ‘reference -
                                                           

    Private HTMLDoc2 As mshtml.IHTMLDocument2

    Protected Friend WithEvents HTMLDOC As HtmlDocument

    Friend Const HTMLSalutation As String = "<html><head>"

    Friend Const HTMLCLose As String = "</body></html>"

    Friend m_editmode as boolean

     

    ‘Initialization

     

    doc = wb.Document.DomDocument

    wb.DocumentText = HTMLSalutation & HTMLCLose

     

     

     

    Public Property GetEditMode() As Boolean

     

            ' This property Gets or Sets the Edit Mode of the webBrowser Control.

            ' This routine saves the WB's contents, sets the Document into design mode and then reloads the control

            Get

                Return m_EditMode

            End Get

            Set(ByVal Value As Boolean)

                If Value Then

                    Dim s As String = wb.DocumentText

                    doc.designMode = "On"

                    wb.DocumentText = s : s = Nothing ‘wb is the webbrowser

                    m_EditMode = True

                Else

                    doc.designMode = "Off"

                    m_EditMode = False

                End If

            End Set

        End Property

     

    Why all of the interest Htmldocs?

    They expose events and methods that are very valuable.

    Once you created these and MSHTML document like HTMLDoc2

    You can use it to issue commands to the webbrowser to set font colors and things in code like this:

     

    Private Sub cbBold_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbBold.Click, _

                                 cbUnderL.Click, cbItalics.Click, cbLeftIndent.Click, cbRightIndent.Click, _

                                 cbLeftJustify.Click, cbRightJustify.Click, cbCenterJustify.Click, cbBItems.Click, _

                                 cbFontColor.Click, cbBackColor.Click

     

            Select Case sender.name

                Case "cbFontColor"

                    Dim colordialogue2 As New ColorDialog

                    If colordialogue2.ShowDialog() <> System.Windows.Forms.DialogResult.OK Then Exit Sub

                    Dim icol As Integer = colordialogue2.Color.ToArgb And &HFFFFFF

                    Dim b As Byte = icol And &HFF

                    Dim g As Byte = icol >> 8 And &HFF

                    Dim r As Byte = icol >> 16 And &HFF

                    HTMLDoc2.execCommand("Forecolor", False, Hex(r) & Hex(g) & Hex(b))

                Case "cbBackColor"

                    Dim colordialogue2 As New ColorDialog

                    If colordialogue2.ShowDialog() <> System.Windows.Forms.DialogResult.OK Then Exit Sub

                    Dim icol As Integer = colordialogue2.Color.ToArgb And &HFFFFFF

                    Dim b As Byte = icol And &HFF

                    Dim g As Byte = icol >> 8 And &HFF

                    Dim r As Byte = icol >> 16 And &HFF

                    HTMLDoc2.execCommand("BackColor", False, Hex(r) & Hex(g) & Hex(b))

                Case "cbBold"

                    HTMLDoc2.execCommand("Bold")

                Case "cbUnderL"

                    HTMLDoc2.execCommand("Underline")

                Case "cbItalics"

                    HTMLDoc2.execCommand("Italic")

                Case "cbLeftIndent"

                    HTMLDoc2.execCommand("Outdent")

                Case "cbRightIndent"

                    HTMLDoc2.execCommand("Indent")

                Case "cbLeftJustify"

                    HTMLDoc2.execCommand("JustifyLeft")

                Case "cbRightJustify"

                    HTMLDoc2.execCommand("JustifyRight")

                Case "cbCenterJustify"

                    HTMLDoc2.execCommand("JustifyCenter")

                Case "cbBItems"

                    HTMLDoc2.execCommand("InsertUnorderedList")

            End Select

        End Sub

     

    Monday, August 6, 2007 3:14 PM

All replies

  •  

    It is possible that whatever SMTP server you are using is converting your HTML message into plain text. 

     

    It is also possible that your message is being delivered as HTML but is being converted to plain text by the recipient's mail client.  Outlook Express for example has a "read all messages in plain text" setting under Tools | Options | Read.

    Monday, August 6, 2007 2:26 AM
  • Hey Pinoyz,  How are you?

     

    If you like, send the email to me and i will see if it shows the font.

    I don't have the plain text set

     

    Monday, August 6, 2007 2:49 AM
  • Hi jeff, i'm fine how about you?

     

             currently our email has a restriction that we're unable to send email outside of our office. but i'll try to find another email that can send outside...

     

     

    here's my code

     

    Send Button

    Dim Email as new System.Net.Mail.MailMessage("myemail@my.com","youremail@your.com")

    Email.Subject = textbox1.text

    Email.Body = Richtextbox1.text

     

    Dim x as new System.Net.Mail.StmpClient("smtp.sample.com")

    Dim net as new System.Net.NetworkCredentials("myemail@my.com","mypassword")

     

    x.Credentials = net

    x.send(Email)

     

    'Font

    Dim x as new FontDialog

    if x.showdialog = Windows.forms.DialogResults.Ok then

    dim s as new Font(x.Font.Fontfamily, x.Font.SizeofPoint, x.Font.Style)

    Richtextbox1.SelectedFont = s

    end if

     

    regards

    Monday, August 6, 2007 3:00 AM
  • I sent some emails to myself and it gave the same result - no format changes just plain text

    There must be way to do it

     

    See what i can come up with tomorrow.

    Monday, August 6, 2007 4:35 AM
  • Ok i did a little trick

     

    I started a new mail message in outlook express

    then in the view menu i selected source edit

    I created a test sentence with a font change

    then i clicked on the source tab

    copied the source

     

    then in my form i pasted the source into a textbox and used a button to put the text in to the richtextbox

    I sent the email and it showed up with the font change shown.

     

    So i guess the deal is that even though your code says  email.isbodyhtml = true

    it's not really html

    it's only plain text in your richtextbox

     

    You may have to code the html code with your text

    How to do that exactly i don't know

     

    Monday, August 6, 2007 4:59 AM
  •  

    I think this is the problem.

     

    Email.Body = Richtextbox1.text

     

    A rich textbook won't work for this application.  Although it will display richly, it will put out either RTF or plain text. This is the plain text output.

     

    You know what you really want for this? You want a webbrowser control in edit mode which will flatout write in HTML and it has a rich set font controls etc. I use it as the editor and word processor in KnowledgeNavigator.

     

    It was just one drawback. As an editor, it double spaces instad of single spaces. The old IE 5 engine used to have hooks so it would single space. I'm space the IE engine has those hooks. I just haven't able to find anyone who knows how to do it.

     

    Renee

    Monday, August 6, 2007 5:14 AM
  • i haven't use webbrowser control can you give me some idea/ somethn

     

     

     

    regards

    Monday, August 6, 2007 6:19 AM
  •  

    You’ve asked a question which has some complexity to it and it requires some expertise. I hope I can best show you in code:

     

    ‘Class member variables

     

    Protected Friend WithEvents doc As New mshtml.HTMLDocument ‘ Will require a  
                                                                ‘reference -
                                                           

    Private HTMLDoc2 As mshtml.IHTMLDocument2

    Protected Friend WithEvents HTMLDOC As HtmlDocument

    Friend Const HTMLSalutation As String = "<html><head>"

    Friend Const HTMLCLose As String = "</body></html>"

    Friend m_editmode as boolean

     

    ‘Initialization

     

    doc = wb.Document.DomDocument

    wb.DocumentText = HTMLSalutation & HTMLCLose

     

     

     

    Public Property GetEditMode() As Boolean

     

            ' This property Gets or Sets the Edit Mode of the webBrowser Control.

            ' This routine saves the WB's contents, sets the Document into design mode and then reloads the control

            Get

                Return m_EditMode

            End Get

            Set(ByVal Value As Boolean)

                If Value Then

                    Dim s As String = wb.DocumentText

                    doc.designMode = "On"

                    wb.DocumentText = s : s = Nothing ‘wb is the webbrowser

                    m_EditMode = True

                Else

                    doc.designMode = "Off"

                    m_EditMode = False

                End If

            End Set

        End Property

     

    Why all of the interest Htmldocs?

    They expose events and methods that are very valuable.

    Once you created these and MSHTML document like HTMLDoc2

    You can use it to issue commands to the webbrowser to set font colors and things in code like this:

     

    Private Sub cbBold_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbBold.Click, _

                                 cbUnderL.Click, cbItalics.Click, cbLeftIndent.Click, cbRightIndent.Click, _

                                 cbLeftJustify.Click, cbRightJustify.Click, cbCenterJustify.Click, cbBItems.Click, _

                                 cbFontColor.Click, cbBackColor.Click

     

            Select Case sender.name

                Case "cbFontColor"

                    Dim colordialogue2 As New ColorDialog

                    If colordialogue2.ShowDialog() <> System.Windows.Forms.DialogResult.OK Then Exit Sub

                    Dim icol As Integer = colordialogue2.Color.ToArgb And &HFFFFFF

                    Dim b As Byte = icol And &HFF

                    Dim g As Byte = icol >> 8 And &HFF

                    Dim r As Byte = icol >> 16 And &HFF

                    HTMLDoc2.execCommand("Forecolor", False, Hex(r) & Hex(g) & Hex(b))

                Case "cbBackColor"

                    Dim colordialogue2 As New ColorDialog

                    If colordialogue2.ShowDialog() <> System.Windows.Forms.DialogResult.OK Then Exit Sub

                    Dim icol As Integer = colordialogue2.Color.ToArgb And &HFFFFFF

                    Dim b As Byte = icol And &HFF

                    Dim g As Byte = icol >> 8 And &HFF

                    Dim r As Byte = icol >> 16 And &HFF

                    HTMLDoc2.execCommand("BackColor", False, Hex(r) & Hex(g) & Hex(b))

                Case "cbBold"

                    HTMLDoc2.execCommand("Bold")

                Case "cbUnderL"

                    HTMLDoc2.execCommand("Underline")

                Case "cbItalics"

                    HTMLDoc2.execCommand("Italic")

                Case "cbLeftIndent"

                    HTMLDoc2.execCommand("Outdent")

                Case "cbRightIndent"

                    HTMLDoc2.execCommand("Indent")

                Case "cbLeftJustify"

                    HTMLDoc2.execCommand("JustifyLeft")

                Case "cbRightJustify"

                    HTMLDoc2.execCommand("JustifyRight")

                Case "cbCenterJustify"

                    HTMLDoc2.execCommand("JustifyCenter")

                Case "cbBItems"

                    HTMLDoc2.execCommand("InsertUnorderedList")

            End Select

        End Sub

     

    Monday, August 6, 2007 3:14 PM
  • ReneeC,

     

    Do you know if the webbrowser component has any licensing agreement to distribute it in a final application?

    Meaning where you have to sign up or pay royalties?

    The Media Player component does but i can't find anything on webbrowser.

    Monday, August 6, 2007 4:25 PM
  •  

    I honestly do not know. My software is freeware. Who knows?
    Tuesday, August 7, 2007 1:31 AM
  • i think, i'm having a hard time to know the webbrowser T_T.

    Tuesday, August 7, 2007 2:43 AM
  •  

    It's only simple after you've done it. Sad
    Tuesday, August 7, 2007 3:52 AM
  • Pinoyz,

     

    I haven't tried it but this may be closer to what you are looking for

     

    Email.Body = Me.RichTextBox1.Rtf

    rtf gets the text and all the rich text format codes

     

     

     

     

    EDIT  nevermind i just tested it and it's not correct

    Thursday, August 9, 2007 12:47 AM
  • I think there's an easier solution using RTB..... i think...

     

    but i'll try 1st Renee suggestion

     

     

     

     

     

    Regards

    Thursday, August 9, 2007 6:08 AM
  • Can any one Help me with my problem... using a webbrowser it's too complicated is there any one site an example for example change of color/ font styles

     

     

    Regards

    Saturday, August 25, 2007 1:33 PM
  • There isn't because the RTB does not put out HTML. It put's out RTF.

    The two are VERY DIfferent.

    Saturday, August 25, 2007 2:45 PM
  • Hi Renee,

     

    Can you give some BASIC example how to change font style... i'm having trouble about your 1st example

    Or you can email me some example (christian_gajo@yahoo.com)

     

    Regards

    Wednesday, August 29, 2007 12:24 AM
  • Pinoyz,

     

    Take it in steps.

     

    The first step is to make code that puts the webbrowser control into edit mode. That is the only way (short of buying an html control) to do this. An alternative is to look for a freeware html control on the net.

    Wednesday, August 29, 2007 2:25 AM
  • i need to purchase a html editor for vb.net or download a freeware html editor?

    Wednesday, August 29, 2007 9:50 AM