Set-ExecutionPolicy RemoteSigned
powershell e:\SendMail.ps1
e:\SendMail.ps1:
#gwmi win32_operatingsystem
Write-Host "Sending Email"
#SMTP server name
$smtpServer = "mail.server.com"
$cred = new-object Net.NetworkCredential("user", "pwd!")
#Creating a Mail object
$msg = new-object Net.Mail.MailMessage
#Creating SMTP server object
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Credentials = $cred
#Email structure
$msg.From = "x@y.z"
$msg.ReplyTo = "x@y.z"
$msg.To.Add("x@y.z")
$msg.subject = "test"
$msg.IsBodyHTML = $true
$msg.body ="
------------ Backup: ---------------------"
$msg.body += Get-Content e:\backuplog.txt
$msg.Attachments.Add('c:\bat\report.txt')
#Sending email
$smtp.Send($msg)
Write-Host "Email Sent"
No comments:
Post a Comment