2018年07月11日
resyncのLogをメール送信させる。
resyncのLogをメール転送させる。
タスクマネージャーから指定時間に batファイル → powershellの流れで処理を行う。
メールサーバーはOCNのホスティングになります。
【sendmail_resync.batの内容】
powershell -NoProfile -ExecutionPolicy Unrestricted C:\sendmail\sendmail_resync.ps1
【sendmail_resync.ps1 の内容】
$user = "user01"
$pass = "*********"
$SmtpHost = "xxxx.mail.com"
$FromAddr = "user01@xxxx.co.jp"
$SmtpPort = 587
$ToAddr = "user01@xxxx.co.jp"
$Date = GET-DATE -Format "yyyy/MM/dd"
$mail = New-Object System.Net.Mail.MailMessage
$mail.from = $FromAddr
$mail.to.Add($ToAddr)
$mail.Subject = "Resync バックアップ状況"
$mail.Body = $Date + "バックアップ状況を転送します。Logファイルの添付がない場合は注意が必要です。"
$FileName = get-date -format yyMMdd
$FilePath="C:\Program Files\rsync193\" + $FileName +".log"
if (Test-Path $FilePath) {
$File=@(Get-ChildItem $FilePath)
$Attachment=New-Object Net.Mail.Attachment($File)
$mail.Attachments.Add($Attachment)
}
$sc = New-Object Net.Mail.SmtpClient($SmtpHost)
$Credentials = new-object System.Net.networkCredential($user, $pass)
$sc.UseDefaultCredentials = $true
$sc.EnableSsl = $true
$sc.Credentials=$Credentials
$sc.Port = $SmtpPort
$sc.Send($mail)
【このカテゴリーの最新記事】
-
no image
-
no image
-
no image
-
no image
-
no image
この記事へのコメント
コメントを書く
この記事へのトラックバックURL
https://fanblogs.jp/tb/7881200
※ブログオーナーが承認したトラックバックのみ表示されます。
※言及リンクのないトラックバックは受信されません。
この記事へのトラックバック