Setting up Database Mail
This recipe demonstrates how to set up Database Mail programmatically using PowerShell.
Getting ready
The assumption in this recipe is that Database Mail is not yet configured on your instance.
These are the settings we will use for this recipe:
Setting |
Value |
---|---|
Mail Server |
|
Mail Server Port |
|
E-mail address for Database Mail profile |
|
SMTP authentication |
Basic authentication |
Credentials for e-mail address |
Username is Password is |
How to do it...
To set up Database Mail, follow these steps:
Open PowerShell ISE as administrator.
Import the SQLPS module and create a new SMO Server object:
#import SQL Server module Import-Module SQLPS -DisableNameChecking #replace this with your actual server name $instanceName = "localhost" $server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $instanceName
Add the following script block to create a Database...