WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

MAPI

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

MAPI and Outlook Security

 Keywords: MAPI Outlook Security OLE Outlook.Application 

Question:

I've been attemping to add some email capabilities to my WinBatch script and have run into a problem. When I try to send an email or even just access the address book I get an error that an outside program is attempting to access the address book.

I have perused the Microsoft knowledgebase and the Security patch is definitely the culprit (by design), but I could find no type of way to get around this. Can anyone help me out with some information on how it would be possible to make it work with the Security patch on and not get these messages, or at least point me in the right direction to look?

Answer:

Since you are building an in-house solution you could probably use the Postie (email) Extender and simply provide it your SMTP mail server address.


Alternatively, you might be able to work around the security dialog using one of the following options:

OPTION 1 - Use Outlook Redemption.

Instead of using the MAPI extender functions you can communicate with Outlook, via OLE and the Redemption COM object. Outlook Redemption works around limitations imposed by the Outlook Security Patch. With Outlook Redemption you can make your code run unaffected by the Security Patch.

http://www.dimastr.com/redemption/

*If* you have Redemption registered on the system, then it should be is accessible to WinBatch. See link above for details.

Sample code:

;!!!UNDEBUGGED!!!
objSafeItem = ObjectOpen("Redemption.SafeMailItem") ;Create an instance of Redemption.SafeMailItem 
objOutlook=ObjectOpen("Outlook.Application")
oItem = objOutlook.CreateItem(0) ;Create a new message
objSafeItem.Item = oItem ;set Item property 
;add recipients
objRecip = objSafeItem.Recipients
To="someone@youknowwhere.org"
;for each address add a recipient
cnt = ItemCount(to,";")
For x = 1 to cnt
	recip = ItemExtract(x,to,";")
   objRecip.Add(recip)
Next
objRecip.ResolveAll

objSafeItem.Body = "Hello...."
objSafeItem.Subject = "Howdy"
objSafeItem.Send 


OPTION 2 - Obtain your own security certificate

Read: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odeopg/html/deovrsigningvbaproject.asp


OPTION 3 - Launch secondary script

Launch a secondary script which waits for the window to exist, then use the control manager extender functions and a SendkeysTo command to acknowledge the dialog.

Note:

You will receive the confirmation dialog box when your script tries to programmatically access the following 
features of the Outlook object model:
 
The AddressEntries collection or any AddressEntry object.
The Recipients collection or any Recipient object.
The following properties of a ContactItem object:
Email1.Address
Email1.AddressType
Email1.DisplayName 
Email1.EntryID 
Email2.Address 
Email2.AddressType 
Email2.DisplayName 
Email2.EntryID
Email3.Address
Email3.AddressType
Email3.DisplayName
Email3.EntryID
NetMeetingAlias
ReferredBy 

The following properties of a MailItem object:
SentOnBehalfOfName
SenderName
ReceivedByName
ReceivedOnBehalfOfName
ReplyRecipientNames
To
Cc
Bcc 

The following properties of a AppointmentItem object:
Organizer
RequiredAttendees
OptionalAttendees
Resources
NetMeetingOrganizerAlias 

The following properties of a TaskItem object:
ContactNames
Contacts
Delegator
Owner
StatusUpdateRecipients
StatusOnCompletionRecipients 

The GetMember method of a DistListItem object.
The ContactNames property of a JournalItem object.
The SenderName property of a MeetingItem object.
The SenderName property of a PostItem object.
The GetRecipientFromID property of a Namespace object.
The Execute method of an Action object.
The Formula property of a UserProperty object.

Here is my code. (Note: this code was designed for Outlook 2002.)

;GETMAIL.WBT
AddExtender("wwctl34i.dll")
olFolderInbox=6 ;constant DO NOT CHANGE
MSapp = ObjectOpen ("Outlook.Application")

objNameSpace = MSapp.GetNamespace("MAPI")
objFolder = objNameSpace.GetDefaultFolder(olFolderInbox); 'Access the Inbox
objFolder.Display
objcount=objFolder.Items
valcount=objcount.Count;checks number of messages in inbox!

For i = 1 to valcount
objItem=objFolder.Items(i) ;set current message
Body = objItem.Body
HTMLBody = objItem.HTMLBody
Subject = objItem.Subject
if i ==1 then Run("c:\temp\killsecurity.wbt","")
WHOTo = objItem.To
Message(WHOTo,StrCat(Subject,@crlf,@crlf,Body))
Next

ObjectClose(MSapp)

exit


;KILLSECURITY.WBT

; Add the control manager extender.

AddExtender("wwctl34i.dll")
totaltry = 5
try = 1
While 1
window1 = cWndByWndSpec("#32770","OUTLOOK",8,4775,4776,4512,4772,4769,4771,4773,4774)
if window1 == 0
timedelay(1)
try = try+1
if try > totaltry then break
continue
endif
winID = cWinIdConvert(window1)
ret = WinWaitExist(winID,3)
if ret
ControlHandle=cWndByID(window1,4774)
While !cEnableState(ControlHandle,-1)
TimeDelay(1)
Endwhile
ControlHandle=cWndByID(window1,4771)
cCheckBox(ControlHandle,1) ;Checks a checkbox
ControlHandle=cWndByID(window1,4774)
;cPostButton(ControlHandle);doesn'twork
;cClickButton(ControlHandle);doesn'twork
SendKeysTo( winID,"{Tab 2}{Enter}")
break
endif
Endwhile
exit

Here is some information Regarding the Outlook security update:

Simple MAPI Design Changes
---------------------------
When Outlook is installed on a computer as the default Simple MAPI client, Outlook processes requests that are made by using Simple MAPI calls. Therefore, when you install the Outlook E-mail Security Update, changes are made to the way that Simple MAPI calls are handled. By default, if you use many Simple MAPI functions you receive a warning message that says a program is trying to either access recipient information or send mail on your behalf.

The following list describes how Outlook responds to Simple MAPI Extedner Functions.

Function			Behavior if handled by Outlook
----------------------------------------------------------------
mFindNext			OK
mLogoff				OK
mLogon				OK
mReadNextMsg		Prompt
mSendMail			Prompt
mSendMailEx			Prompt

Here are some links to Microsoft about the Outlook security update:

OL2000: Developer Information About the Outlook E-mail Security Update http://support.microsoft.com/support/kb/articles/Q262/7/01.ASP

OL2000: Administrator Information About the Outlook E-mail Security Update http://support.microsoft.com/support/kb/articles/Q263/2/97.ASP


Article ID:   W15059
File Created: 2017:07:28:13:58:31
Last Updated: 2004:02:02:10:19:55