Availability of PR_HTML Property in MapiMessage and MailMessage

When we construct a MapiMessage, set PR_HTML property, and send the message to the target, PR_HTML property is available.

Message construction example:

 using (MapiMessage mapiMessage = new MapiMessage())
                    {
                        mapiMessage.Subject = "test";
                        mapiMessage.Body = "test bodyy";
                        mapiMessage.SetProperty(new MapiProperty(MapiPropertyTag.PR_HTML, Encoding.Unicode.GetBytes(byteArray)));
                        
                        if (mapiMessage.Properties.ContainsKey(MapiPropertyTag.PR_HTML))// this condition is true
                        {
                            
                        }
                    }

When we construct a MapiMessage from MailMessage using FromMailMessage(mailMessage), set PR_HTML property, and send the message to the target, PR_HTML property is NOT available.

Message construction example:

 using (var ms = new MemoryStream(byteArray))
						{
							using (MailMessage mailMessage = MailMessage.Load(ms))
							{
								using (MapiMessage mapiMessage = MapiMessage.FromMailMessage(mailMessage))
								{
									mapiMessage.SetProperty(new MapiProperty(MapiPropertyTag.PR_HTML, byteArray));

									if (mapiMessage.Properties.ContainsKey(MapiPropertyTag.PR_HTML))// this condition is true
									{

									}

								}
							}
						}

Why PR_HTML property is available in the first case, while NOT available in the second one?

@merge1,
Welcome to our community! Thank you for posting the query. Unfortunately, I cannot use your code snippets containing the unknown symbol byteArray to investigate the issue on our side. Please share a comprehensive code example and email file (if the file is required) to investigate the problem.

Hi,

Thanks for the response.
Please see below the code snippets which describe the issue more accurately.

MapiMessage construction example 1:
using (MapiMessage mapiMessage = new MapiMessage())
{
mapiMessage.Subject = “test”;
mapiMessage.Body = “test bodyy”;
mapiMessage.SetProperty(new MapiProperty(MapiPropertyTag.PR_HTML, Encoding.Unicode.GetBytes(htmlBody)));

                    if (mapiMessage.Properties.ContainsKey(MapiPropertyTag.PR_HTML))// this condition is true
                    {
                        
                    }
                }

MapiMessage construction example 2:
using (var ms = new MemoryStream(byteArray))
{
using (MailMessage mailMessage = MailMessage.Load(ms))
{
using (MapiMessage mapiMessage = MapiMessage.FromMailMessage(mailMessage))
{
mapiMessage.SetProperty(new MapiProperty(MapiPropertyTag.PR_HTML, Encoding.Unicode.GetBytes(htmlBody)));

								if (mapiMessage.Properties.ContainsKey(MapiPropertyTag.PR_HTML))// this condition is true
								{

								}

							}
						}
					}

I also attach the file. You can use this file represented by byteArray to investigate the issue.

message.zip (30.8 KB)

@merge1,
Thank you for the EML file. Unfortunately, I cannot use your code snippets containing the unknown symbol htmlBody. You should share complete code examples so that we can help you.