O'Reilly logo

SQL Server 2014 with PowerShell v5 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

E-mail address for Database Mail profile

dbmail@queryworks.local

SMTP authentication

Basic authentication

Credentials for e-mail address

Username is dbmail@queryworks.local

Password is <some password>

How to do it...

To set up Database Mail, follow these steps:

  1. Open PowerShell ISE as administrator.
  2. Import the SQLPS module and create a new SMO Server object:
    #import SQL Server module Import-Module SQLPS ...

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