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 |
|
Email Address for Database Mail Profile |
|
SMTP Authentication |
Basic authentication |
Credentials for Email Address |
Username: Password: |
How to do it...
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
Add the following script...