More Outlook Resource Sites

Microsoft Developer Network (MSDN)

FAQs and other general resources

Login

login
password
Remember me

You will need to register and log in if you want to download the source code for the Microsoft Outlook Programming book. The forums and code sharing areas are open to both registered and non-registered visitors.

share code 09-Sep-2010 05:55

Looking for help with Outlook programming projects — VSTO, add-ins, VBA, custom Outlook forms, etc.? You′ve come to the right place!

NEW! >> Subscribe to this site via RSS. For more RSS options, see the complete list of feeds on our main news page.

 

Code level: advanced    Code area: Outlook and .NET Printer Friendly Version
Title: Avoid Security Propmts / Access MAPI Properties
Description: This sample shows howto access MAPI Properties directly from C# without additional Libraries. Can be used in or outside AddIn and with VS2003 and VSTO 2005
Date: 18-Nov-2005  21:57
Code level: advanced
Code area: Outlook and .NET
Posted by: Helmut Obertanner
Body:
All 95comments
Page [ 1 2 3 4 5 6 7 8 9 10 Next >>  
  13-Dec-2005  05:17   
I tried this and it works great for let's say PR_SENDER_NAME. However... when I try to get the PR_HTML of a Task item, the error 'Arithmetic operation resulted in an overflow' is thrown when the body is returned in the GetMessageProperty function.
  21-Dec-2005  14:09   
Yeah, the same error for me. when i tried to use PR_ENTRYID...
Is this anything to do with unit or ulong??
  06-Feb-2006  15:16   
Try wrapping it in a unchecked { } block.
  08-Feb-2006  08:28   
The above code snippet works fine if my default mail client is set as Outlook.But the problem comes if Outlook is not default mail client then GetMessageBody() returns " "

How to tackle this ?...
 
  27-Feb-2006  06:25   
This seems to work fine, but it looks using PR_BODY_W does not return the unicode clear text body.

Here is what I does:

I have an utf-8 body example in a plaintext message.
When I try to read it in Outlook 2002/XP, it is shown decoded (japanese & russian visible).

When I try to read it from the MAPIOBJECT using the above method, I get "?" instead of the correct bytes. I've tried to read the body as ansi (0x1e) or as unicode (0x1f). It does not work. (XP SP2 / Outlook XP SP3 installed)

The same experiment with HTML works perfectly fine.

As a sidenote, it looks Outlook 2003 (any SP) is unable to read utf-8 encoded plaintext messages. Even if he made those messages and if they are perfecrly readable with Outlook 2002, a webmail or Thunderbird. ("?" instead of the unicode characters) I wonder if it is related.
 
  27-Feb-2006  06:28   
I forgot to say that if I try to read the same plaintext message from the MailItem.Body, the unicode characters were there.

I would like to be able to retrieve the body, even in its raw form. (My main goal is not to avoid the warning, it is to avoid that strange Outlook 2003 issue)

No luck so far.
 
  28-Feb-2006  05:09   
Hello Eric,
as I know sometimes the MAPI function returns not directly a string, sometimes it returns a stream. I tried, but i didn't get it working with pure C# managed code.
If I ever get it working i will put the sources here.

Greets, Helmut
  21-Apr-2006  01:16   
Hi Helmut,

This article has been very useful !!

I had one query regarding SMTP addresses:
PR_SENDER_EMAIL_ADDRESS property from IMailuser returns an SMTP or EX address. Suppose we need to get the sender's SMTP address only.

How could we get the sender's SMTP address using MAPI?

Also, is there a way to get the IAddrBook interface in C# using MAPI.

Thanks and Regards,
Bikram
  21-Apr-2006  01:46   
Hello Bikram,

theoretically "Yes" ! - It's only a question of time. With this sample I'll gave you a small proof of concept code that works specially for this problem. I have the problem, that I didn't figured out how to deal with the variant properties and steams from unmanaged MAPI code to managed C# code. Theorethically everything is possible, because you can get the Interface by it's guid and retrive the property that you like.
The technique should be the same like in this sample anove, just another Interface.

Hope this helps,
greets, Helmut Obertanner
 
  25-Aug-2006  05:42   
I' modified this code to set the PR_SENDER_NAME value to see right names in my postItems. But it works queer: i see set phrase if i open postitem, and in "quick view" window. But in folder i see the word "Unknown", and in my program PostItemObject.SenderName return "Unknown". So, I'd greatly appreciate, if you mention me how to set all PR_SENDER_... properties of the PostItem. I need to set SenderName an RecievedTime. Ind I need user not to see any "Sender" of the PostItem. Just the "Name" of Item.
Thanks a lot for your example!
Page [ 1 2 3 4 5 6 7 8 9 10 Next >>  
Post your comment



name        email