December 20, 2005 at 11:35 am
Hi there, I have a script that writes (and formats) output from a query to a text file. What I want to do is use that text file as the body of an email that will be sent out. I have written the following script (bits taken from around the internet) but the problem I have is that is sends out seperate emails per line of the text file.
For example if my text file contained:
This
Is
A
Text
File
I would get five seperate emails with the message:
This
Is
A
Text
File
So far my script is:
declare @objFSys int
declare @objFile int
declare @blnEndOfFile int
declare @strLine varchar(4000)
exec sp_OAMethod @objFSys, 'OpenTextFile', @objFile out, 'C:\textfile.txt', 1
exec sp_OAMethod @objFile, 'AtEndOfStream', @blnEndOfFile out
while @blnEndOfFile=0 begin
exec @blnEndOfFile = sp_OAMethod @objFile, 'ReadLine', @strLine out
print @strLine
declare @out varchar(8000)
declare @From varchar(200)
declare @To varchar(200)
declare @subject varchar(300)
declare @SMTPServer varchar(100)
declare @minimumspace int
declare @body Varchar(8000)
set @minimumspace = 15
set @SMTPServer ='My SMTP server'
set @From ='my email address'
set @To ='my email address'
set @subject = 'my subject'
set @body = @strLine
exec sp_OAMethod @objFile, 'AtEndOfStream', @blnEndOfFile out
end
exec usp_send_cdosysmail @From ,@To ,@Subject,@Body,@SMTPServer
exec sp_OADestroy @objFile
exec sp_OADestroy @objFSys
December 21, 2005 at 6:28 am
Why not put the content of your text file into the message body directly ?
December 21, 2005 at 10:28 am
The text file is dunamically created every hour and may contain different data (it reports on Error logs of various servers).
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply