Powershell script to send e-mails, loosing text in e-mail attachment
Posted
by Beuy
on Server Fault
See other posts from Server Fault
or by Beuy
Published on 2010-05-10T23:47:21Z
Indexed on
2010/05/10
23:55 UTC
Read the original article
Hit count: 304
powershell
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?
© Server Fault or respective owner