O'Reilly logo

Microsoft® SQL Server 2012 Unleashed by Alex T. Silverstein, Chris Gallelli, Paul T. Bertucci, Ray Rankins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

General Tasks

Often you might be required to send out emails containing particular reports and/or output from commands run.

To do so, you use features from the .NET Framework via PowerShell to send out emails, as shown in here:

Function Send-Mail {param([string]$To,[string]$From,[string]$Subject, `  [string]$Body,[string]$File,[string]$SmtpServer)  If($SmtpServer -eq ""){    $SmtpServer = "FQDN of your SMTP server here"  }  $Smtp = New-Object System.Net.Mail.SMTPclient($SmtpServer)  $Message = New-Object  System.Net.Mail.MailMessage($From,$To,$Subject,$Body)  If ($File -ne "") {    $Attach = New-Object System.Net.Mail.Attachment $File    $Message.Attachments.Add($Attach)  }  $smtp.Send($message)}

You can enter the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required