StringConversionConfig Class
Provides properties the developer can use to affect how the values of string properties of MailMessage and dependent objects should be charset-converted when being returned to the application.
Inheritance Hierarchy
SystemObject
  MailBee.MimeStringConversionConfig

Namespace: MailBee.Mime
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 11.2.0 build 590 for .NET 4.5
Syntax
public class StringConversionConfig

The StringConversionConfig type exposes the following members.

Methods
  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Properties
  NameDescription
Public propertyConversionMode
Gets or sets the mode of charset conversion of the values of string properties of MailMessage object.
Public propertyCustomByteEncoding
Gets or sets the base encoding of the returned values of string properties of MailMessage object.
Public propertyDestinationEncoding
Gets or sets the charset of the returned values of string properties of MailMessage object.
Top
Remarks

This class is for advanced use. Use it only if have web application which is non-Unicode (not UTF-8) and you need to avoid conversion of the mail message data into the response charset. This may happen when ASP.NET produces the page output (which consits of 8-bit bytes, not 16-bit Unicode chars) and thus converts the data from strings into bytes. The default conversion into the response charset may cause loss of characters which are not defined in this charset.

To avoid this, MailBee can simulate that the message data belong to the system charset while this is actually not so. The details of "string to byte and back to string" approach are:

  1. Convert a string into bytes accordingly the appropriate character encoding (this encoding can be taken from the charset information of the message or hardcoded using DestinationEncoding property).
  2. Convert the bytes into a string accordingly CustomByteEncoding (prior to that, the application should set CustomByteEncoding to the value of responseEncoding setting of web.config file) and return the resulting string to the application.
  3. Then, ASP.NET takes the string generated at the previous step and puts it into the response buffer (which is a byte stream) by converting it from the string into bytes (i.e. opposite action). Since ASP.NET uses the same responseEncoding for that, the resulting byte array will be exactly the same as the one generated at the first step (the second and the third steps compensated each other). This way, the client will receive the same bytes which have been generated by MailBee (these bytes hold the message data encoded in the original message charset or in DestinationEncoding charset). Thus, no characters will be lost when ASP.NET produces the page response and thus converts the string data into responseEncoding even if the string data contain characters which are not defined in responseEncoding charset.
Because the client will receive the message data in the charset specified in the message (or in DestinationEncoding charset), you should also properly set META tag of the HTML data received by the client. You can use MailMessage.Parser.CharsetMetaTagMode property for this. However, if you have not hard-coded the desired charset with DestinationEncoding property and send the message data in its original charset, you should also take care of any other non-ASCII data you may be sending in the server response. For instance, if the HTML data you're sending to the client browser also contain any labels with international characters (such as localized UI elements), they may render incorrectly if they belong to another charset (not the one used the message was composed in). The typical workaround is to HTML encode any international characters so they would become charset independent.

In short, the main purpose of this class is to transfer the given byte data (as it appears in the message) to the client provided that this data will pass through ASP.NET response generator which accepts only strings. This means the byte data should be wrapped into strings using the same encoding used by ASP.NET to convert them from strings back to bytes. You should set this encoding via CustomByteEncoding property.

With this class it's also possible to modify the encoding of the byte data itself (DestinationEncoding property). It affects the charset of the data the client will receive. Or, you can tell MailBee to retain the original charset encoding of the data as it appears in the message.

To set a particular mode of the charset conversion, use ConversionMode property.

Note Note
This class cannot be used on its own. To access its members, use MailMessage.Parser.CharsetConverter property.
See Also