0
votes

I get error in Message.Body.BodyType while sending email: you must load or assign this property before you can read its value

if (service != null)
{
       Microsoft.Exchange.WebServices.Data.EmailMessage message = new Microsoft.Exchange.WebServices.Data.EmailMessage(service);

       message.Subject = SendMail.Subject;
       if (SendMail.IsHtml)
       {
           message.Body.BodyType = Microsoft.Exchange.WebServices.Data.BodyType.HTML;
           message.Body = new Microsoft.Exchange.WebServices.Data.MessageBody(SendMail.Html);
       }      
}
1

1 Answers

0
votes

You should be using the BodyType parameter in the MessageBody Overload to set the BodyType eg

if (service != null)
{
      Microsoft.Exchange.WebServices.Data.EmailMessage message = new Microsoft.Exchange.WebServices.Data.EmailMessage(service);

      message.Subject = SendMail.Subject;
     if (SendMail.IsHtml)
     {
            message.Body = new Microsoft.Exchange.WebServices.Data.MessageBody(Microsoft.Exchange.WebServices.Data.BodyType.HTML,SendMail.Html);
     }      
}

And that should work, the property your trying to use is only useful when reading an existing message.

Cheers Glen