Change the MiniIcon in a message

  • Thread starter Thread starter ghislain
  • Start date Start date
G

ghislain

Hello,

I would like to change the MiniIcon of an email.

I use this code but it doesn't change it :

Dim currInspector As Outlook.Inspector =
Globals.ThisAddIn.Application.ActiveInspector
Dim message As Outlook.MailItem =
CType(currInspector.CurrentItem, Outlook.MailItem)
message.FormDescription.Icon = "C:\Program Files\Microsoft
Office\Office12\FORMS\1033\TASKACCL.ICO"
message.FormDescription.MiniIcon = "C:\Program Files\Microsoft
Office\Office12\FORMS\1033\TASKACCS.ICO"

message.FormDescription.PublishForm(Outlook.OlFormRegistry.olDefaultRegistry)
message.Save()

Could you please help me ?

Have a nice day

Regards

Ghislain
 
Does the form have a custom message class?

If you look at an item using the form with a MAPI viewer such as OutlookSpy
(www.dimastr.com) or MFCMAPI do you see a property there PR_ICON_INDEX? If
so does it have a value of -1? You would need to set that if it's not set
to -1 and is there.

That property isn't exposed in the Outlook object model so you'd have to use
a different API such as CDO or Extended MAPI or Redemption if not using
Outlook 2007. For Outlook 2007 you can use the PropertyAccessor object with
a property tag of "http://schemas.microsoft.com/mapi/proptag/0x10800003".
 
What do you mean it doesn't work? That's the correct property tag for
PR_ICON_INDEX. That property may not be there, it's not a required property
on an item. If it's not there Outlook automatically uses the default icon
for that item type. If it's there an index value means Outlook is using one
of its standard item icons, if it's set to -1 it uses whatever icons you
specify in the FormDescription.Icon and .MiniIcon properties.




Thanks for all those informations

Yes I'm using Outlook 2007 but your link
http://schemas.microsoft.com/mapi/proptag/0x10800003
doesn't work.

Ghislain
 
It works !!!

Thank you very much.

For information, here you are my code

Dim currInspector As Outlook.Inspector =
Globals.ThisAddIn.Application.ActiveInspector
Dim message As Outlook.MailItem = CType(currInspector.CurrentItem,
Outlook.MailItem)
message.PropertyAccessor.SetProperty("http://schemas.microsoft.com/
mapi/proptag/0x10800003", 1)
message.FormDescription.Icon = "C:\Program Files\Microsoft Office
\Office12\FORMS\1033\TASKACCL.ICO"
message.FormDescription.MiniIcon = "C:\Program Files\Microsoft Office
\Office12\FORMS\1033\TASKACCS.ICO"
message.Save()

Ghislain
 
Set PR_ICON_INDEX to -1, not 1.




It works !!!

Thank you very much.

For information, here you are my code

Dim currInspector As Outlook.Inspector =
Globals.ThisAddIn.Application.ActiveInspector
Dim message As Outlook.MailItem = CType(currInspector.CurrentItem,
Outlook.MailItem)
message.PropertyAccessor.SetProperty("http://schemas.microsoft.com/
mapi/proptag/0x10800003", 1)
message.FormDescription.Icon = "C:\Program Files\Microsoft Office
\Office12\FORMS\1033\TASKACCL.ICO"
message.FormDescription.MiniIcon = "C:\Program Files\Microsoft Office
\Office12\FORMS\1033\TASKACCS.ICO"
message.Save()

Ghislain
 
Hi,

So seems like it's possible to set any icon to MailItem.

Is it possible in VSTO 2005?? For Outlook 2003???



Thanks.
 
VSTO has nothing to do with it. Outlook 2003 doesn't have a
PropertyAccessor() object and provides no access to the PR_ICON_INDEX in the
Outlook object model. Therefore you'd have to access that property using an
alternate API. Since Extended MAPI (C++ and Delphi only) and CDO 1.21 are
both not supported for use with managed code your alternatives are MAPI
wrappers such as Redemption (www.dimastr.com/redemption) or MAPI33 or such.
 
Thanks for replay.

My AddIn developed on VSTO 2005, C#. Also i'm using Redemption
however didn't find any solution, could you please provide me some
sample regarding this.


Thanks in advance.
 
Well, if you have a MailItem in your code (myMail) to use Redemption with it
would be something like this:

Redemption.SafeMailItem safMail = new Redemption.SafeMailItem();
const int PR_ICON_INDEX = 0x10800003;
safMail.Item = myMail;
int propTag = safMail.GetIdsFromNames
safMail.SetFields(PR_ICON_INDEX, -1);
myMail.Subject = myMail.Subject; // fool Outlook into thinking something has
changed
myMail.Save();

That would set the icon index. That would be the only part where you'd have
to use Redemption code, the rest would be similar to the code Ghislain
posted.
 
Thanks,

I tried your suggestion i wrote the same snippet (except of this line
of code: int propTag = safMail.GetIdsFromNames , i didn't understand
it's reason.)
also i added the Ghislain code, however i doesn't see the Icon.

Any suggestion??
 
The GetIdsFromNames line should have been deleted, I forgot to do that. It's
not needed since PR_ICON_INDEX isn't a MAPI named property but is a standard
property with a property tag value of 0x10800003.

With that code and the other code supplying the icons to use you should see
the icons unless the icon path isn't valid for your system or something else
is wrong. No errors?
 
Thanks.

I didn't get any error ( for test reason i provide dummy path for the
icen, and got en exception "File not found" ).

Any ideas??

Thanks in advance.
 
If you got a file not found error then you are providing an incorrect path
or the file doesn't exist.
 
Ken,

Concerning the "File not found" i excplicitly did it, just to chech
wheterer the code is running.
I provide a right path, and don't get any exception however the icon
doesn't chenged.


Any ideas??

Thank you.
 
Here's what I suspect is happening: Setting any FormDescription properties in an individual item will have no effect, because current versions of Outlook ignore one-off FormDescription information. The solution would be to use a published custom form (or in Outlook 2007, a form region manifest).
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
Thanks Sue,

What do u meanby saying "The solution would be to use a published
custom form ", can explain please, or provide
some sample???
Another question, the AddIn developed for Outlook 2003 on VSTO 2005,
C# 2.0, also the AddIn works fine in Outlook 2007
the " Outlook 2007, a form region manifest", can be used in my
situation??? (I'm using Redemption in my code.)


Thanks in advance.
 
Try it for yourself: Create a new message form and on the (Properties) page set the icon. Publish it to your Personal Forms library, ignoring any prompt to check the "Send form definition with item box." Now, change the value of the MessageClass property of any message to the published form's class, e.g. "IPM.Note.MyForm." You should see the message icon change.

Form regions are for Outlook 2007 only.
 
Back
Top