Outlook Add-in Problems

A

Adam

Hey Guys,



Here's the scenario, I am writing an outlook add-in that will
cross-reference all of the recipients of an email against a user defined
data source to see if the contact is a corporate contact. If one of the
recipients is in the corporate contacts list then it adds an email address
to the BCC field of the MailItem object.



I actually have 2 problems here.



1) Every time I run this process outlook stops everything
and alerts me that some application is trying to access my contacts list and
if want I can allow it for 1,2,3,4 or 10 minutes. This is unacceptable due
to business specifications so I need to find a workaround for this.



2) When I try to add the email address to the BCC field
none of my error handling fires but outlook pops up with a nice little
message saying "operation failed" . gotta love the descriptive error message
... This happens where ever I try to do this. The thing is that after I get
that message It leaves the message open and I can see the email address I
tried to add in the BCC field so I'm not exactly sure what part fails but
I'm
at my wits end



Here's the code:

'OMF is a class I built that actually does all the processing



'The ItemSend Event:



Public Sub applicationObject_ItemSend(ByVal Item As Object, ByRef Cancel
As Boolean) Handles applicationObject.ItemSend



Dim str As String

str = OMF.Send(Item, applicationObject)

Item.BCC = str

End Sub



'The OMF.Send Function

'the isContact works fine and Me.Email is a property holding the email
address to add to the BCC field

'oA is a global Outlook Application



Public Function Send(ByRef mail As Outlook.MailItem, ByRef app As
Outlook.Application) As String

'variables

oA = app

Trace = 1

Dim ret As String = "none"

Dim strTo As String()

Dim strRead As String

Trace = 2

Try

strTo = mail.To.Split(emailTokens)

Trace = 3

For Each rep As String In strTo

Trace = 4

If isContact(rep) Then

Trace = 15

If Not IsNothing(mail.BCC) Then

Trace = 155

If InStr(mail.BCC.ToString, ";") Then

Trace = 16

ret = Me.Email

Else

Trace = 17

ret = Me.Email

End If

Else

ret = Me.Email

End If



End If

Next

Catch ex As SystemException

MessageBox.Show("Trace " & Trace & vbNewLine & "Error: " &
vbNewLine & ex.Message & vbNewLine & "Stack Trace:" & vbNewLine &
ex.StackTrace)

writeError(ex)

End Try

Return ret

End Function




This needs to be compatible with Outlook / Exchange 2000 +

Any help or input would be greatly appreciated guys



TIA

- Adam
 
S

Sue Mosher [MVP-Outlook]

1) See http://www.outlookcode.com/d/sec.htm for your options with regard to the "object model guard" security in Outlook 2000 SP2 and later versions.


2) Use MailItem.Recipients.Add, not MailItem.Bcc, and resolve the recipient.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
A

Adam

Hello Sue,

First things first, I would just like to think you for taking the time to
help me out with my problem.

In regards to adding a BCC I ended up using a collaboration of your advice
and the advice from another reply in a separate newsgroup.

This is what it looks like to those who would like to know.

Dim str As String
Dim Recip As Outlook.Recipient

str = OMF.Send(Item, applicationObject)

Recip = Item.Recipients.Add(str)

Recip.Type = 3 ' 3 = BCC

Item.Recipients.ResolveAll()

Cancel = False
str = Nothing
Recip = Nothing

This is using VB.NET which I should have specified in my original post but
this works fine.

Now the problem still lies in the "Object Model Guard" I followed the link
you left for me (thx again) and I spent the better part of the day reading
that article and almost all of the articles that spawned from that one. Now
I must say I am more confused now then ever. I have written a "Windows
Service" using VB.NET that will populate an "Exchange" folder with contacts
from a SQL DB and I didn't run into any of these problems. Basically what I
think could be a source of the problem is that when the OnConnection sub is
called

Public Sub OnConnection(ByVal application As Object, ByVal connectMode
As Extensibility.ext_ConnectMode, ByVal addInInst As Object, ByRef custom As
System.Array) Implements Extensibility.IDTExtensibility2.OnConnection

It is getting application as "ByVal" which is creating a new un-trusted
application object. Is there a way for me to change that to "ByRef" and then
just pass that "trusted" application object around to my functions to do the
required processing?

If not would you happen to maybe have an example of bypassing this "Object
Modal Guard" that you wouldn't mind sharing?

Once again thanks

- Adam


1) See http://www.outlookcode.com/d/sec.htm for your options with regard to
the "object model guard" security in Outlook 2000 SP2 and later versions.


2) Use MailItem.Recipients.Add, not MailItem.Bcc, and resolve the recipient.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

Sue Mosher [MVP-Outlook]

You have it wrong, I'm afraid. The application object passed by the OnConnection event *is* "trustable" with regard to the Outlook "object model guard." But only Outlook 2003 supports the concept of "trusted" add-ins on standalone machines. In an Exchange environment, an add-in can be trusted for all versions that support trusted add-ins using the Outlook Security Settings public folder. For a .NET add-in, you will need a shim and will trust the shim using the security settings form.

For add-ins that must support multiple versions and multiple environments, the best solution would be to write your own Extended MAPI component to handle the methods you need, but that's not a .NET project. As a VB/VB.NET programmer, I use Redemption in my projects, and you'll find plenty of samples on the Redemption web site.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

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