O'Reilly logo

SQL Server 2012 with PowerShell V3 Cookbook by Donabel Santos

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

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.queryworks.local

Mail Server Port

25

Email Address for Database Mail Profile

dbmail@queryworks.local

SMTP Authentication

Basic authentication

Credentials for Email Address

Username: dbmail@queryworks.local

Password: <somepassword>

How to do it...

  1. Open the PowerShell console by going to Start | Accessories | Windows PowerShell | Windows PowerShell ISE.
  2. Import the SQLPS module and create a new SMO Server object, as follows:
    #import SQL ...

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