PowerShell script to send out an email,
$LogTime = Get-Date -Format yyyy-MM-dd_hh-mm
$LogFile = ".\SendEmailPatch-$LogTime.rtf"
# Add SharePoint PowerShell Snapin
if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) {
Add-PSSnapin Microsoft.SharePoint.Powershell
}
$scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent
Set-Location $scriptBase
#Deleting any .rtf files in the scriptbase location
$FindRTFFile = Get-ChildItem $scriptBase\*.* -include *.rtf
if($FindRTFFile)
{
foreach($file in $FindRTFFile)
{
remove-item $file
}
}
start-transcript $logfile
function sendMail{
Write-Host "Sending Email"
$smtpServer = "SMTP Server Address"
$message = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$message.From = "Email from address"
$message.ReplyTo = "Email reply to address"
$message.To.Add("To address")
$message.subject = "Subject for the email"
$message.body = "Body for the email"
$smtp.Send($message)
}
####Calling function####
sendmail
#################### 