Outlook XP HTMLBody property

Add-in Express™ Support Service
That's what is more important than anything else

Outlook XP HTMLBody property
 
Guest


Guest


Hi,

I want to create a new HTML message and send it in my add-in. Below code works fine with outlook 2000, but in XP, message appears blank. What can be the problem? (If i use Body property rather than HTMLBody, it works OK in both versions, but I want to send an html message.)

Regards,
Serhat.

Public Sub SendEmailNotification(ByVal emailAddress As String, ByVal rmNotificationHTML As String, ByVal firmName As String)
Dim newMail As Outlook.MailItem
Dim o As Object = Outlook.OlItemType.olMailItem
Try
newMail = Connect.applicationObject.GetType().InvokeMember("CreateItem", Reflection.BindingFlags.GetProperty, _
Type.DefaultBinder, Connect.applicationObject, New Object() {o})
newMail.To = emailAddress
newMail.Subject = "GP Database files saved for " + firmName + "."
newMail.HTMLBody = rmNotificationHTML
CType(newMail, Outlook._MailItem).Send()
Catch
Finally
If Not newMail Is Nothing Then
Marshal.ReleaseComObject(newMail)
End If
End Try
End Sub
#End Region
Posted 14 Jan, 2006 11:55:44 Top
Brad Smith




Posts: 49
Joined: 2005-11-22
I'm going from memory here, since I haven't messed with this in .NET at all. But if memory serves you need to explicitly set the BodyFormat properly to olFormatHTML.
I think OLXP defaults to RTF format, and will do an RTFSync from RTF (which is empty) to HTML on Send, thus losing your changes.
Note that BodyFormat doesn't exist in Outlook2000, so you will have to get at that property the "hard way". I'm sure Sergey can point you towards (or whip up) the correct VB code fragment.

Post back if this works (or doesn't).

Brad.
Posted 15 Jan, 2006 18:17:18 Top
Sergey Grischenko


Add-in Express team


Posts: 7228
Joined: 2004-07-05
Hi Serhat.

Try the code below:


private enum BodyFormat: int
{
olFormatUnspecified = 0,
olFormatPlain = 1,
olFormatHTML = 2,
olFormatRichText = 3
}

private void adxCommandBarButton1_Click(object sender)
{
object currentItem = null;
Outlook.MailItem mail = null;

Outlook._Inspector inspector = OutlookApp.ActiveInspector();
if (inspector != null)
{
try
{
currentItem = inspector.CurrentItem;
if (currentItem is Outlook.MailItem)
{
mail = currentItem as Outlook.MailItem;
mail.Subject = "Here is my subject.";
if (OutlookApp.Version.IndexOf("9.0") == -1)
mail.GetType().InvokeMember("BodyFormat" , BindingFlags.SetProperty, null, mail, new object[]{(int)BodyFormat.olFormatHTML});
mail.HTMLBody = <your HTML string>;
mail.Save();
}
}
finally
{
if (currentItem != null)
Marshal.ReleaseComObject(currentItem);
Marshal.ReleaseComObject(inspector);
}
}
}
Posted 16 Jan, 2006 09:48:49 Top
Guest


Guest


Hi,

Thanks for replies.

I have already tried to set the BodyFormat property to html using Outlook XP PIA but unfortunately, result was same.

Sergey,

In XP, I can't hook to active explorer object for some reason(it is always null.?) I will try more for it, but the code you have suggested did not seem very proper to me. For example, what if the current item is not a mail object? Why do i have to use an existing mail object to create a new mail (there can be no mail items in users outlook at all)?

Thanks a lot,
Serhat.
Posted 16 Jan, 2006 13:19:48 Top
Guest


Guest


Now that's strange.

It turned out that code was actually working fine. The fact is that I never actually sent the message when i was testing it (offline mode), but checking the message body on my outbox. It was (and is ) simply blank.

But I have gone through the net, and found out that the mail that is sent actually contains the correct HTML body (tested&verified that by sending message to myself). For some strange reason, when mail is moved to outbox after it is sent, its body appears to be blank, but the body of the sent message is OK..

Posted 16 Jan, 2006 18:21:46 Top
Sergey Grischenko


Add-in Express team


Posts: 7228
Joined: 2004-07-05
Hi Serhat.

I am a little confused. I tested the code above in Outlook XP (SP3). All works fine on my PC. You can download an example using the following link:
http://www.add-in-express.com/projects/htmlbodyexample.zip
Also please make sure that the new message format is HTML (see the 'Format' menu in the new mail inspector).
Posted 17 Jan, 2006 05:54:53 Top
serhat adali




Posts: 5
Joined: 2006-01-26
Sergey, thank you very much for your efforts. Your sample works fine, and I have figured out why I was having strange problems like having null for active explorer. I did not understand the nature of the problem though.

Here is the problem (I know that it gets quite unrelated with the topic, but I did not want create a private thread for it.)

Suppose I have a windows form that I present to user on some certain occasions like clicking a custom button on the toolbar etc.

Now, passing some objects as parameters in constructor of the windows form causes add-in function improperly. When I install the Add-in, it does no use the .dll files on the installation path, but uses the .dll files in the bin folder of the project. If i delete the .dll in bin folder, add-in stops functioning. On computers other than development computer, setup deploys the project but add-in does not work.

About those objects,
one example is Outlook.Selection object. The strange point is that if I declare the parameters as objects, it works fine. But if declare them as Outlook objects, (Outlook.Selection in this example) this errorus behaviour occurs.


Public Sub New(OLSelection as object).... 'works fine

Public Sub New(OLSelection as Outlook.Selection )... ' causes the mentioned error.

I am using .Net framework 1.1, VS.Net 2002/2003 and Outlook 2000 PIA.

Has anybody encountered such a strange behaviour before?

Regards,
Posted 26 Jan, 2006 05:05:33 Top
Sergey Grischenko


Add-in Express team


Posts: 7228
Joined: 2004-07-05
Hi Serhat.

I think your add-in uses the wrong dlls because the add-in is already registered when you install it via the msi package on the same PC. Do you unregister the add-in when you test the installation?
As for another PC, I think the installation doesn't register the add-in properly. You can send me the project if you wish. I will test it.

Has anybody encountered such a strange behaviour before?

Do you use our PIAs for Office 2000?

Posted 26 Jan, 2006 11:22:09 Top
serhat adali




Posts: 5
Joined: 2006-01-26
No, I do not unregister the add-in when testing. The problem can be because of the PIA too. About a year ago, I hit a bug in Outlook 2000 PIA, and I have dissambled&assembled it after removing the bug. (It was something about the eventhandlers, and I had to change some helper methods from private to public according to the msdn documentation)

From that time on, I am using the same Outlook 2000 PIA that I have modified. I did not use your PIA. (I was'nt aware of "your" PIA. What is it?)

I have modified the project, but I will backout the changes to reproduce the behaviour and send it to you. Thank you very much for your help sergey.

Regards,
Serhat.
Posted 27 Jan, 2006 17:18:24 Top