I have a rule that operates on all emails received via a particular account.

All these emails have an attachment. The rule runs a script.
The script copies the email item into a local object and then calls Attachment.SaveAsFile using a file name that I construct. It then uses the Shell function to start a VB Express program with a command line parameter that is the file name.

If I send an email to the account myself, from my computer or via GMail, everything works great. The email is saved, the external program ruins and operates on the attachment and the world is a happy place.

When I receive an email from another external domain it fails. A box is presented on the screen. The box is titled "Rules in Error". The rule name is shown and the error is "The operation failed. An object could not be found".

Since the rule always works fine when I send the email and always fails when a message is sent from an external source I suspect that this is a security problem. Outlook has a personal email account and a gmail pop account and if the email comes from either of these sources it works.

I've checked and the self-generated emails and the external emails are exactly the same. The only difference is the source / sender address.

I've spent 3 days trying to fix this with no luck.

If anyone can assist I'd really appreciate it.

I've attached the outlook script code below.

---------------------------------------------------------------
Sub ExtractAttachment(MyMail As MailItem)
' -------------------------------------------------------------------------------------------------------
' The purpose of this routine is to extract for processing attachments from emails
' that are received from xxxxxxxxxxxxxx.
'
' Outlook passes the new email item as MyMail. To avoid the Outlook security system, the mail item is
' copied into a temporary MailItem structure.
'
' The file name is constructed by concatenating the name of the sender then the filename of the attachment with an "@" sign
' between them
' --------------------------------------------------------------------------------------------------------

Dim olAtt As Attachment
Dim i As Integer
Dim strID As String
Dim NewFileName As String
Dim CmdLine As String

' Create a MailItem to copy the actual message into
Dim objMail As Outlook.MailItem
' Change the next line to reflect where you want the renamed attachment to be stored
Const FILE_PATH As String = "C:\newdata\"

' Get the EntryID of the incoming message and use it to create a copy of the message in objMail
strID = MyMail.EntryID
Set objMail = Application.Session.GetItemFromID(strID)
' Construct the file name to save the attachment with
Sender = Left(objMail.SenderEmailAddress, InStr(objMail.SenderEmailAddress, "@") - 1)

' We only expect a single attachment per email but just in case...
If objMail.Attachments.Count > 0 Then
For i = 1 To objMail.Attachments.Count
Set olAtt = objMail.Attachments(i)
NewFileName = FILE_PATH & Sender & "@" & olAtt.FileName
olAtt.SaveAsFile NewFileName
' And then run a program to do something about the new attachment
CmdLine = FILE_PATH & "NewFileReceived.exe -f " & NewFileName
Shell (CmdLine)
Next
End If
Set objMail = Nothing
End Sub