2

I need to check if a file exist into a path.

if yes, I need to send it as attachment of mail.

this my code now:

$file='STREAM_preg.txt'
$pathfile ='c:\Users\root\Desktop'
$dest ='C:\Users\root\Desktop\test'

cd $pathfile
if(Test-Path $file){
        $datestamp = get-date -uformat "%Y%m%d%H%M"
    Copy-Item $file $dest\$datestamp"_"$file
    $new_file = echo $datestamp"_"$file
    echo $new_file
      # Send-MailMessage -SmtpServer xxxxxxxxxx -To pluto@pippo.com -From preg_new_stream@pippo.com -Subject "test mail" -Body "file name is: $new_file"
}else{
        echo false
}
4

2 回答 2

6

Send-Mailmessage接受要附加的文件路径。

Send-MailMessage -SmtpServer xxxxxxxxxx -To pluto@pippo.com -From preg_new_stream@pippo.com -Subject "test mail" -Body "file name is: $new_file" -attachment $new_file
于 2013-04-10T15:58:44.743 回答
0

Send-mailmessage 将一个或多个文件路径作为附件的管道输入。只需将文件路径通过管道发送到该 send-meailmessage 命令,它就会作为电子邮件的附件发送。

于 2013-04-10T15:57:25.757 回答