Hopefully that subject makes sense...
I have a variety of scripts that do stuff, output to text file, and then use vbscript to send it to me in an e-mail. I've been working on getting some of these converted over to PowerShell, and everything works fine, except when I try to e-mail it. When the e-mail arrives in my mailbox, it is usually just a couple wing-ding characters, like it's not reading the text file properly or there are some hidden chars. Here's my vbscript code:
If I open the output file from PowerShell in notepad, I can read it fine, Wordpad as well. If nobody's seen anything like this before, I'll assume it's a problem with PowerShell and pursue this from that angle.
I have a variety of scripts that do stuff, output to text file, and then use vbscript to send it to me in an e-mail. I've been working on getting some of these converted over to PowerShell, and everything works fine, except when I try to e-mail it. When the e-mail arrives in my mailbox, it is usually just a couple wing-ding characters, like it's not reading the text file properly or there are some hidden chars. Here's my vbscript code:
Code:
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("c:\freespace.txt", ForReading)
BodyText = f.ReadAll
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "me@mail.com"
objEmail.To = "me@mail.com"
objEmail.Subject = "Server Disk Space"
objEmail.TextBody = BodyText
objEmail.Configuration.Fields.Item _
("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing")[/URL] = 2
objEmail.Configuration.Fields.Item _
("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver")[/URL] = _
"smtprelay"
objEmail.Configuration.Fields.Item _
("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserverport")[/URL] = 25
objEmail.Configuration.Fields.Update
objEmail.Send
If I open the output file from PowerShell in notepad, I can read it fine, Wordpad as well. If nobody's seen anything like this before, I'll assume it's a problem with PowerShell and pursue this from that angle.