This recipe demonstrates how to set up Database Mail programmatically, using PowerShell.
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 |
|
Email Address for Database Mail Profile | |
SMTP Authentication |
Basic authentication |
Credentials for Email Address |
Username: Password: |
Open the PowerShell console by going to Start | Accessories | Windows PowerShell | Windows PowerShell ISE.
Import the
SQLPS
module and create a new SMO Server object, as follows:#import SQL Server module Import-Module SQLPS -DisableNameChecking #replace this with your instance name $instanceName = "KERRIGAN" $server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $instanceName