Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object Required error when checking Outlook email with vbScript

Status
Not open for further replies.

samiam445

Programmer
Oct 3, 2012
2
US
The script runs successfully when run in the editor or from the command line while logged on to the server. When logged off and called from another application, it returns an 'Object Required' error.

strSubject is passed to the script as an argument and script returns 1 if email subject is found or 0 if not.

Any assistance is appreciated.

----------------------------
Const olFolderInbox = 6

Set olApp = CreateObject("Outlook.Application")
Set olns = olApp.GetNameSpace("MAPI")
Set objFolder = olns.GetDefaultFolder(olFolderInbox)
Set myItems = objFolder.Items

intStatus = 0
For iCount = 1 To myItems.Count
Set MyItem = MyItems(iCount)
If myItem.Subject = strSubject then
intStatus = 1
Exit For
End if
Next

WScript.Quit intStatus
--------------------------------
 
Not exactly sure. Consider "permissions". I've quoted it because I kind of mean it. If the account that is running this script does not have a valid email account, an outlook object will not be created.

-Geates

"I do not offer answers, only considerations."
- Geates's Disclaimer

 
Thanks, Geates. Is there a way to login to the email account in the script when checking the inbox for the email?

The email is being forwarded from a clients Exchange box to verify mail flow. We configured Outlook 2010 on the server with the special email account it is forwarded to.

When I am logged in to the server as Administrator and run the script in the editor, or manually from a batch file (to verify the return code), it works. Running the batch file as a scheduled task with the admin credentials hangs in the running state. Calling it from another program fails to return a successful return code.

If I could login with the email credentials from the script it should return a success return code to the program.

 
Interesting. If it works while logged in as Administrator - I assume "Administrator" doesn't have an email account - then what I mentioned before, "If the account that is running this script does not have a valid email account, an outlook object will not be created", is untrue. Although, it seems logically true.

You could try using an administrative user account credentials to see if you get a different response.

-Geates


"I do not offer answers, only considerations."
- Geates's Disclaimer

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top