You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
function sendmail()
|
|
|
|
|
{
|
|
|
|
|
function mailoptions($mailaddr,$body) #<EFBFBD><EFBFBD><EFBFBD>巢<EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>ķ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
$msg=New-Object System.Net.Mail.MailMessage
|
|
|
|
|
$msg.To.Add($mailaddr)
|
|
|
|
|
$msg.From = New-Object System.Net.Mail.MailAddress("notice@test.com", "<EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><EFBFBD><EFBFBD>Ա",[system.Text.Encoding]::GetEncoding("UTF-8")) #<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
$msg.Subject = "Windows<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>֪ͨ<EFBFBD><EFBFBD>"
|
|
|
|
|
$msg.SubjectEncoding = [system.Text.Encoding]::GetEncoding("UTF-8")
|
|
|
|
|
$msg.Body =$body
|
|
|
|
|
$msg.BodyEncoding = [system.Text.Encoding]::GetEncoding("UTF-8")
|
|
|
|
|
$msg.IsBodyHtml = $false #<EFBFBD><EFBFBD><EFBFBD><EFBFBD>html<EFBFBD><EFBFBD>ʽ<EFBFBD>ʼ<EFBFBD>
|
|
|
|
|
$client = New-Object System.Net.Mail.SmtpClient("smtp.qiye.163.com") #<EFBFBD><EFBFBD><EFBFBD><EFBFBD>smtp<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
$client.Port = 25 #ָ<EFBFBD><EFBFBD>smtp<EFBFBD>˿<EFBFBD>
|
|
|
|
|
$client.UseDefaultCredentials = $false
|
|
|
|
|
$client.Credentials=New-Object System.Net.NetworkCredential("notice@test.com", "xxxxxxxx")
|
|
|
|
|
try {$client.Send($msg)}
|
|
|
|
|
catch [Exception]
|
|
|
|
|
{$($_.Exception.Message)
|
|
|
|
|
$mailaddr
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$tomailaddr = "ops@test.com"
|
|
|
|
|
mailoptions $tomailaddr $Emailbody
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$Emailbody= "Dear All :
|
|
|
|
|
"
|
|
|
|
|
|
|
|
|
|
$counter= 0
|
|
|
|
|
|
|
|
|
|
#test<EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if (Get-ChildItem D:\serverbackup\WindowsImageBackup\test\Catalog | Where{$_.LastWriteTime -lt (Get-Date).AddDays(-32)})
|
|
|
|
|
{
|
|
|
|
|
$Emailbody= $Emailbody +
|
|
|
|
|
"
|
|
|
|
|
<EFBFBD><EFBFBD> test<EFBFBD><EFBFBD>10.8.8.1<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
"
|
|
|
|
|
$counter= $counter + 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$Emailbody= $Emailbody +
|
|
|
|
|
"
|
|
|
|
|
<EFBFBD>澯<EFBFBD><EFBFBD>Դ 127.0.0.1
|
|
|
|
|
"
|
|
|
|
|
|
|
|
|
|
if ($counter -gt 0)
|
|
|
|
|
{
|
|
|
|
|
sendmail
|
|
|
|
|
}
|