Вы находитесь на странице: 1из 4

ProProfs.

com [CONFIGURING DATABASE MAIL IN SQL SERVER]

Configuring Database Mail


Database Mail allows you to send messages from SQL Server2005. Database Mail replaces previous
version of SQL Server’s mail agent, SQL Mail. New features found in Database Mail include:

 Support for multiple email profiles/accounts


 Asynchronous messaging
 Cluster-awareness
 64-bit compatibility
 Improved security
 Mail auditing
 Usage of SMTP (eliminates need for Extended MAPI)

Setting up Database Mail

First, you must enable Database Mail (it is disabled by


default):

1. On the machine running SQL Server 2005, open


SQL Server Surface Area Configuration.

2. Select “Surface Area Configuration for Features”.

3. Once the dialog box opens, select the SQL Server


2005 instance you want to configure, and then
expand the Database Engine Node.

4. Select the Database Mail Node.

5. Check the “Enable Database Mail


Stored Procedures” checkbox.

6. Click “Apply” and then “OK”. You


are now done with Surface Area
Configuration.
ProProfs.com [CONFIGURING DATABASE MAIL IN SQL SERVER]

As an alternative to enabling Database Mail, you can execute T-SQL code, or more specifically, a stored
procedure. Ensure you are logged in as a sysadmin, and run:

To disable Database Mail, run the following code:

The second step in configuring Database Mail is to ensure that Service Broker is enabled in the msdb
database (enabled by default). To enable this, stop the SQL Server Agent and run the following:

The third step is necessary only if the SMTP server requires authentication. If this is the case, you need
to ensure that the SQL Server service (default) account credentials can access the server.

Database Mail Architecture

There are four components to Database Mail:

1. Configuration components: includes two sub-components:


a. Database Mail account, which includes the SMTP server name, authentication type, and
e-mail address.
b. Database Mail profile, which is a collection of Mail accounts. Used by applications to
send e-mail to profiles (and accounts can later be added/deleted without code re-write).

2. Messaging: the Database Mail host database (msdb)


ProProfs.com [CONFIGURING DATABASE MAIL IN SQL SERVER]

3. Database Mail executable: DatabaseMail90.exe, a separate executable from SQL Server to


minimize impact. Connects to the database engine via the SQL Server service account
credentials.

4. Logging and Auditing: Log information is stored in the host database (msdb). Query the
sysmail_event_log view to see the log.

Using the Database Mail Configuration Wizard

This wizard allows you to perform actions including account


management, profile setup, and security.

1. Expand the Management Node, right click Database


Mail, and choose “configure Database Mail”.

2. This will give you the welcome screen for the


Database Mail Configuration Wizard. Click Next, and
select “Set up Database Mail by performing the
following tasks” is selected (which is by default).
Click Next.

3. Enter the Profile name, a brief description, and then


“Add” a new SMTP account.

4. Fill in the Account information, click


okay, and review your settings.

5. Specify database users or roles that


can access the database profile.
Public Profiles can be accessed by all
users; Private Profiles can only be
accessed by a specific user of a mail-
host database.

6. You now have Database Mail


configured!
ProProfs.com [CONFIGURING DATABASE MAIL IN SQL SERVER]

To verify that Database Mail is setup correctly, go back to the Management Node and right-click
Database Mail. Select “Send Test Email…” Specify the recipient’s email address, and click “Send Test
Email”. You should receive an email similar to the following:

To view the Database Mail log, simply expand the Management Node, right-click Database Mail, and
select “View Database Mail log”:

Вам также может понравиться