Powershell script to send e-mails, loosing text in e-mail attachment
- by Beuy
I have the following function to send e-mails in powershell with attachments:
function SendMail(){
if($e -ine '')
{
$mail = New-Object System.Net.Mail.MailMessage
$mail.From = $f;
$mail.To.Add($t);
$mail.Subject = $s;
$att = New-Object System.Net.Mail.Attachment –ArgumentList $l
$mail.Attachments.Add($att)
$mail.Body = $b;
$smtp = New-Object System.Net.Mail.SmtpClient($serv);
$smtp.Send($mail);
}
}
When I try to send a .txt file attachment it seems to strip out all of the information from within the text file. Any suggestions as to what's going wrong?