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

Get SQL Server 2014 with PowerShell v5 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.