Log in

View Full Version : How Use rules and VBA on shared accounts?



SvenBlomme
07-10-2015, 01:51 AM
I hope someone can help me with following problem.

in my company we use shared accounts per project, which are accessible by all team members.
All incoming emails (which are sent to the project account) are processed with server side rules, and automatically filed in the correct subfolders.
This works quite well. However, some emails also end up in the shared account inbox by means of dragging and dropping (so not by actually sending the email to the account), and if this happens, the server side rules do not run. I tried to work around this by dragging and dropping the emails in a subfolder, from which they can be moved to the parent inbox with a button macro (which works perfectly well), but this apparently also does not trigger the rules when the moved emails 'arrive' in the inbox.
I have full permissions and also have the user and password for the shared account, but I would like to avoid having to change between profiles all the time, as this would lead to error 'I'm not the only one who would need to switch constantly, so this will surely introduce errors at some point).

So basically, my question is, how can I fire a rule on the inbox of a shared account, without being logged in, if the email is dragged and dropped into the folder rather than actually being sent?

Any help would be very welcome.

skatonni
07-13-2015, 02:24 PM
Add the shared account Mailbox to your own profile.

See itemAdd information here http://www.outlookcode.com/article.aspx?id=62

See Run Rules Now sample here http://www.vboffice.net/en/developers/run-rules-now


Option Explicit

' Should look like this untested code
' In ThisOutlookSession
Private WithEvents olSharedMailboxInboxItems As Items

Private Sub Application_Startup()
Dim objNS As Namespace
' This code is applicable where the shared mailbox is added to your profile
Set objNS = Application.GetNamespace("MAPI")
On Error GoTo SharedMailboxNotInProfile
Set olSharedMailboxInboxItems = objNS.Folders("SharedMailbox Name").Folders("Inbox").Items
On Error GoTo 0
Debug.Print vbCr & "Adding items to the - Shared Mailbox Inbox will trigger SharedMailboxInboxItems_ItemAdd"
GoTo ExitRoutine
SharedMailboxNotInProfile:
Debug.Print "olSharedMailboxInboxItems_ItemAdd works if SharedMailbox is in the profile."
ExitRoutine:
Set objNS = Nothing
End Sub

Private Sub SharedMailboxInboxItems_ItemAdd(ByVal Item As Object)

If TypeOf Item Is MailItem Then

MsgBox "Item added to SharedMailboxInbox."

' Rules apply to the folder not the added message
' In the rule you will likely want to move the item so it is not processed again

End If

End Sub