winston1984
IS-IT--Management
I have the following code, but everything works well, except there is no attachment. The file exists afterwards but it just doesn't attach it.
Function Main()
On Error Resume Next
dim strRecord
dim strEmailBody
dim objFSO
dim objStream
dim objMail
dim objResults
dim strFileToAttach
strFileToAttach = "E:/SQLOUTPUT/PRICE.TXT"
const OUTPUT_FILE = "E:\SQLOUTPUT\PRICE.TXT"
const EXECUTIVE_EMAILS = "lewis@lharvey.com"
const fsoForWriting = 2
set objFSO = CreateObject("Scripting.FileSystemObject")
set objResults = DTSGlobalVariables("gResults").Value
set objStream = objFSO.OpenTextFile(OUTPUT_FILE, fsoForWriting, true)
'Loop through the records and output each one
'to a file.
while not objResults.EOF
strRecord = "ISONID = " & objResults.Fields(0).value & vbCrLf &_
"ISON7PRICE = " & objResults.Fields(1).value & vbCrLf &_
"STOCK PRICE = " & objResults.Fields(3).value
objStream.WriteLine(strRecord)
objStream.WriteBlankLines(1)
objResults.MoveNext
wend
'Sending a text email with an attached file
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Example CDO Message"
objMessage.Sender = "me@my.com"
objMessage.To = "lewis@lharvey.com"
objMessage.TextBody = "This is some sample message text."
objMessage.AddAttachment strFileToAttach
objMessage.Send
if err.count = 0 then
Main = DTSTaskExecResult_Success
else
Main = DTSTaskExecResult_Failure
end if
End Function
Running MS Server 2003 SBE.
Function Main()
On Error Resume Next
dim strRecord
dim strEmailBody
dim objFSO
dim objStream
dim objMail
dim objResults
dim strFileToAttach
strFileToAttach = "E:/SQLOUTPUT/PRICE.TXT"
const OUTPUT_FILE = "E:\SQLOUTPUT\PRICE.TXT"
const EXECUTIVE_EMAILS = "lewis@lharvey.com"
const fsoForWriting = 2
set objFSO = CreateObject("Scripting.FileSystemObject")
set objResults = DTSGlobalVariables("gResults").Value
set objStream = objFSO.OpenTextFile(OUTPUT_FILE, fsoForWriting, true)
'Loop through the records and output each one
'to a file.
while not objResults.EOF
strRecord = "ISONID = " & objResults.Fields(0).value & vbCrLf &_
"ISON7PRICE = " & objResults.Fields(1).value & vbCrLf &_
"STOCK PRICE = " & objResults.Fields(3).value
objStream.WriteLine(strRecord)
objStream.WriteBlankLines(1)
objResults.MoveNext
wend
'Sending a text email with an attached file
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Example CDO Message"
objMessage.Sender = "me@my.com"
objMessage.To = "lewis@lharvey.com"
objMessage.TextBody = "This is some sample message text."
objMessage.AddAttachment strFileToAttach
objMessage.Send
if err.count = 0 then
Main = DTSTaskExecResult_Success
else
Main = DTSTaskExecResult_Failure
end if
End Function
Running MS Server 2003 SBE.