"illegal char" error when creating new AlternateView

0 votes
asked Apr 25, 2011 by timo (260 points)
edited Apr 26, 2011


I am using your Rebex Mail and have some problems creating an alternateview and add it to the message. The htmlbody is simple html and comes from a richedit-control. When i try this by using Net.Mail objects its working fine:

Dim view As Net.Mail.AlternateView = Net.Mail.AlternateView.CreateAlternateViewFromString(htmlBody, Encoding.UTF8, MediaTypeNames.Text.Html)

The Rebex.Mail.AlternateView does not have an "CreateAlternateViewFromString"-method so i try it this way:

Dim view As New Rebex.Mail.AlternateView(htmlBody, MediaTypeNames.Text.Html)

but always get an error, something like "illegal char found in the path".

Maybe the missing encoding-info is the problem? Would be nice if someone has an idea about this.

Thanks, Timo

Applies to: Rebex Secure Mail

1 Answer

+1 vote
answered Apr 26, 2011 by Lukas Matyska (60,770 points)
edited Apr 26, 2011
Best answer

Please note the arguments of the AlternateView constructor. It is only a fileName or contentStream, not contentString itself. To create AlternateView from string you can use following code:

Dim ms As New MemoryStream(Encoding.UTF8.GetBytes(htmlBody))
Dim view As New Rebex.Mail.AlternateView(ms, MediaTypeNames.Text.Html)
commented Apr 26, 2011 by timo (260 points)
edited Apr 26, 2011

Hi Lukas, thanks for that! Thought it was too late at night for coding this part ...