How to get MailItem.Body without security warning in Outlook 2010

T

Tom

Hi,

Now I run the following code in Outlook 2010, it shows security warning
dialog. My question is that how to go without the dialog.

MailItem oMailItem

' here it is true that oMailItem is valid object

str = oMailItem.Body ' this line cause security warning

The test is
"A program is trying to acces e-mail address information stored in Outlook.
If this is unexpected, click Deny and verity your antivirus software is
up-to-data.

For more information about e-mail safety and how you might be able to avoid
getting this warning, click help."

Next is a check box for "Allow access for" right is a dropdown combobox "1
minute"

The last is 3 buttons as "Allow", "Deny" and "Help", in which "Deny" is
default one.

=======================================
For what I know now is that when calling oMailItem.Body, Outlook will
extract string text from RTF format stored internally (but I am not sure if
it is so in Outlook 2010). And both Body & HTMLBody are protected now. Any
access to them will prompt warning dialog unless anti-virus program is
up-to-date. Unfortunately our program will assume to running in user's
machine with/without anti-virus applications.

=======================================
I also try to use MAPI library with C++ code. It has no security warning
dialog when I get the email text like code:

IMessage* pMsg;
IStream* pStream;
STATSTG stg = {0};
....

// here pMsg & pStream are valid pointers
pMsg->OpenProperty(PR_BODY, &IID_IStream, STGM_READWRITE, 0,
(IUnknown**)&istream);
pStream->Stat(*stg, 0);
int bodysize = stg.cbSize.LowPart; // won't bother checking for >2gb messages!
char* bodybuf = new char[bodysize+1];
ULONG red;
HRESULT hr = pStream->Read(bodybuf, bodysize, &red);

// I am able to get email body text without security warning
// however if I try to change email body, return code is "access deny" like

std::string strtest;
strtest = bodybuf;
strtest += " test";
hr = pStream->->Write(strtest, strtest.GetLength(), &red);

Any suggestion?
Thanks in advance.

Tom
 
M

Michael Bauer [MVP - Outlook]

The important part is missing: how do you get the MailItem? You need to
derive it from the instrinsic Application object, that is not from an
Application variable created by GetObject or CreateObject.

--
Best regards
Michael Bauer - MVP Outlook
Manage and share your categories:
<http://www.vboffice.net/product.html?pub=6&lang=en>


Am Thu, 14 Jan 2010 10:21:02 -0800 schrieb Tom:
 
T

Tom

Hi Michael,

I get the MailItem object as following code sample. The code is written in
C++ with Outlook import.

=======================================
#import "C:\Program Files\Common Files\microsoft shared\OFFICE14\mso.dll"
#import "C:\Program Files\Microsoft Office\Office14\MSOUTL.OLB"
rename_namespace("Outlook")

void test()
{
Outlook::_ApplicationPtr spApp("Outlook.Application");

if (NULL == spApp)
{
hr = spApp.CreateInstance("Outlook.Application");
}

if (spApp)
{
// from now on spApp is the valid Outlook.Application object in VBA
Outlook::_ExplorerPtr spExplorer = spApp->ActiveExplorer();
if (spExplorer)
{
Outlook::SelectionPtr spSel = spEcplorer->GetSelection();
if (spSel && spSel->Count == 1) // if only 1 selection
{
// assume that the selection is a mail item
Outlook::_MailItemPtr spMailItem = spSel->Item(1);
// the following line will bring up the security warning
dialog
::OutputDebugString(spMailItem.Body);
}
}
}
}

=======================================

Other than the security warning dialog and if I click "allow", the output
text is exactly as the content of the email item I selected.

Thanks,

Tom


Michael Bauer said:
The important part is missing: how do you get the MailItem? You need to
derive it from the instrinsic Application object, that is not from an
Application variable created by GetObject or CreateObject.

--
Best regards
Michael Bauer - MVP Outlook
Manage and share your categories:
<http://www.vboffice.net/product.html?pub=6&lang=en>


Am Thu, 14 Jan 2010 10:21:02 -0800 schrieb Tom:
Hi,

Now I run the following code in Outlook 2010, it shows security warning
dialog. My question is that how to go without the dialog.

MailItem oMailItem

' here it is true that oMailItem is valid object

str = oMailItem.Body ' this line cause security warning

The test is
"A program is trying to acces e-mail address information stored in Outlook.
If this is unexpected, click Deny and verity your antivirus software is
up-to-data.

For more information about e-mail safety and how you might be able to avoid
getting this warning, click help."

Next is a check box for "Allow access for" right is a dropdown combobox "1
minute"

The last is 3 buttons as "Allow", "Deny" and "Help", in which "Deny" is
default one.

=======================================
For what I know now is that when calling oMailItem.Body, Outlook will
extract string text from RTF format stored internally (but I am not sure if
it is so in Outlook 2010). And both Body & HTMLBody are protected now. Any
access to them will prompt warning dialog unless anti-virus program is
up-to-date. Unfortunately our program will assume to running in user's
machine with/without anti-virus applications.

=======================================
I also try to use MAPI library with C++ code. It has no security warning
dialog when I get the email text like code:

IMessage* pMsg;
IStream* pStream;
STATSTG stg = {0};
...

// here pMsg & pStream are valid pointers
pMsg->OpenProperty(PR_BODY, &IID_IStream, STGM_READWRITE, 0,
(IUnknown**)&istream);
pStream->Stat(*stg, 0);
int bodysize = stg.cbSize.LowPart; // won't bother checking for >2gb messages!
char* bodybuf = new char[bodysize+1];
ULONG red;
HRESULT hr = pStream->Read(bodybuf, bodysize, &red);

// I am able to get email body text without security warning
// however if I try to change email body, return code is "access deny" like

std::string strtest;
strtest = bodybuf;
strtest += " test";
hr = pStream->->Write(strtest, strtest.GetLength(), &red);

Any suggestion?
Thanks in advance.

Tom
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top