I currently have a process that recurses through some directories on the network, saves some information to a CSV, and then I import the CSV once to send it out again using Out-File so it looks readable by doing the following:
$CSV = Import-Csv -Path $LogPath
$CSV | Out-File -FilePath $LogPath2
This code works fine. $Logpath is the csv, $LogPath2 is a .txt. I use the following code to send the results in an email via bmail.exe:
Start-Process -FilePath 'D:\Scheduled\BMAIL\bmail.exe' -ArgumentList '-s SMPTServerName -t ToThisEmail@test.com -f FromThisEmail@test.com -h -a "Email Subject Line" -c -m FileToShowContentInEmail'
The FileToShowContentInEmail is the .txt file generated from the Out-File line above, but the result in the email it sends is this:
ÿþ
I've tried specifying -Encoding ascii,default,utf8,utf7,oem, all of the encoding options for that Out-File command, but they all either return those weird characters in the email or it will actually have the information in the email but it is unaligned and hard to read/follow.
This process is being ran as a .ps1 on a ftp server as a scheduled task. How can I get this to send the .txt file's content in an email and it be formatted correctly? When I go and view the .txt, it is formatted fine just not in the email. I can't use PowerShell's Send-MailMessage due to some policies/rules put in place on our domain so bmail.exe was the workaround.