Hi Guys

I have built an exe file using VB 6.0. This exe is scheduled using the scheduler in SQL Server 7.0. I am trying to send mails to a certain people (individual mails) and am using the Microsoft Outlook 8.0 object Library.

The problem is that these people don't get the mails and the exe doesn't come with up with any errors. I am mentioning the code that i have in the exe file below. To find out exactly whats heppening, i created a text file which records every event as it happens. When i run the exe, i get all the messages in the text file showing me that the process of sending mails went through without errors but actually, no mails have been sent. I then double-clicked on the exe itself and it works that way. But when the exe is run from the scheduler, it is unable to send mails. Could someone help? The code is as below:

---------------------------------------------------------------------------------

Sub SendEmailToSelfAsTest()

On Error GoTo Error_Handler

Dim strMailMsg As String
Dim objOutlook As Outlook.Application
Dim olNameSpace As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Dim objMailItem As Outlook.MailItem
Dim intFileNo As Integer

'Write the Status of sending Mails to the MailStatus.txt text file
fstrErrFileName = App.Path & "\MailStatus.txt"

intFileNo = FreeFile
Open fstrErrFileName For Append As #intFileNo

Set objOutlook = CreateObject("Outlook.Application")
'Write Status to File
Write #intFileNo, "Created Outlook object"

Set olNameSpace = objOutlook.GetNamespace("MAPI")
'Write Status to File
Write #intFileNo, "Created Namespace object"

olNameSpace.Logon '"sysadmin", "password", False, True
'Write Status to File
Write #intFileNo, "Logged on"

Set objFolder = olNameSpace.GetDefaultFolder(olFolderOutbox)
Set objMailItem = objFolder.Items.Add(olMailItem) 'objOutlook.CreateItem(olMailItem)
'Write Status to File
Write #intFileNo, "Created Mail object"

objMailItem.Recipients.Add "[email protected]"
'Write Status to File
Write #intFileNo, "Added Receipient"

objMailItem.Subject = "Test subject Message"
'Write Status to File
Write #intFileNo, "Added Subject"

objMailItem.Body = "This message is sent as a test."
'Write Status to File
Write #intFileNo, "Added Body"

objMailItem.Send
'Write Status to File
Write #intFileNo, "Sent Mail"

'Close the references to the Outlook objects
Set objMailItem = Nothing
Set objFolder = Nothing
olNameSpace.Logoff
Set olNameSpace = Nothing
objOutlook.Quit
Set objOutlook = Nothing

'Write Status to File
Write #intFileNo, "Closed References to objects"
Close #intFileNo

Exit Sub

Error_Handler:
'Write Status to File
Write #intFileNo, "[" & CStr(Err.Number) & "] " & Err.Description
Close #intFileNo

End Sub