Download - 14806 Database Mail
-
8/6/2019 14806 Database Mail
1/31
Database Mail
Microsoft SQL Server 2005 includes a new andimproved method for message delivery to and from theSQL Server.
This feature, known as Database Mail, allows SQL tosend and receive messages throughSMTP delivery.
Messages can be generated from within SQL and caninclude attachments from outside of the SQL
environment. Database Mail uses the msdb database for storing
configuration information about Database Mail
-
8/6/2019 14806 Database Mail
2/31
Cont
The Database Mail feature uses accounts to
configure access to SMTP servers, and profiles to
configure access to mail accounts. However, profiles
and accounts can be mutually exclusive. You cancreate accounts without an association with a
profile, and you can use the same account with
multiple profiles, if necessary.
-
8/6/2019 14806 Database Mail
3/31
How to Configure Database Mail
The easiest way to configure SQL Server to use Database
Mail is through the Database Mail Configuration Wizard
in SQL Server Management Studio.
To launch the wizard, navigate to the Management
section of your server in Object Explorer .
Expand Management, right-click Database Mail, and
select Configure Database Mail.
-
8/6/2019 14806 Database Mail
4/31
-
8/6/2019 14806 Database Mail
5/31
Configuring Database Mail
The first page you will see is simply a start page thatexplains each of the following steps in the wizard. Ifyou dont want to see this page again, select thecheckbox at the bottom of the page indicating you wish
to skip this page in the future.
On the next screen, youll be asked to identify whichconfiguration task youre using the wizard to perform.
You can use this to initialize Database Mail for use onthis server; or, if its already configured, you
can manage existing mail profiles and configuredaccounts. You can also change system settings
-
8/6/2019 14806 Database Mail
6/31
-
8/6/2019 14806 Database Mail
7/31
Cont
Database Mail is disabled by default.
If this is the first time youve run this wizard, and havenot manually enabled Database Mail, you will be
prompted to enable it. Once youve enabled Database Mail, Once that
information has been entered, you must configure atleast one account that this profile will use.
The ability to configure multiple accounts under a singleprofile helps guarantee the availability of theDatabase Mail feature to users who need to receiveinformation, and path of delivery isnt relevant.
-
8/6/2019 14806 Database Mail
8/31
Cont..
To create a new account, click the Add button. In the NewDatabase Mail Account screen,enter in an account name anddescription, and then information about the account,including the email address that the messages will originate
from, the display name for that address, the reply-toaddress, and the name or IP address of the SMTP server.
There is also a box where you can enter the port number
used by the SMTP server.
you know that your server uses a different port, you should
use the standard SMTP port, 25. If your server uses SecureSockets Layer (SSL) to protect the data in-transit,
select the appropriate checkbox.
-
8/6/2019 14806 Database Mail
9/31
Cont..
The order in which the accounts are listed will
determine the order of precedence when sending
messages.
Once youve entered in the information about the
account, click OK to close the New Database Mail
Account window. You can enter in more accounts to
be used by the same profile, or you can continue onto the next screen by clicking Next.
-
8/6/2019 14806 Database Mail
10/31
Cont..
select the method of authentication the SMTP server
requires. By default, Anonymous authentication is
selected, but this is not the preferred method for
most SMTP servers.
If your SMTP server is Windows-based, you may be
able to use Windows Authentication using Database
Engine service credentials. Otherwise, you can use Basic authentication,
providing a username and password manually.
-
8/6/2019 14806 Database Mail
11/31
-
8/6/2019 14806 Database Mail
12/31
Cont..
Next screen will ask you to provide information for
a new Database Mail profile. Enter a name for the
profile, and optionally a description to help identify
the profile and how it will be used.
On the Manage Profile Security screen, you can use
the Public Profiles tab to elect to make the profilepublic.
-
8/6/2019 14806 Database Mail
13/31
-
8/6/2019 14806 Database Mail
14/31
-
8/6/2019 14806 Database Mail
15/31
-
8/6/2019 14806 Database Mail
16/31
Configuring Database Mail Options
After Database Mail has been enabled, you can
use the sysmail_configure_sp stored procedure.
The syntax of the sysmail_configure_sp stored
procedure is as follows:
sysmail_configure_sp [ @parameter_name = ]
name , [ @parameter_value = ] value,
[ @description = ] description
-
8/6/2019 14806 Database Mail
17/31
sysmail_configure_sp
The sysmail_configure_sp stored procedure
lives in the msdb database.
EXECUTE msdb.dbo.sysmail_configure_sp
MaxFileSize, 4194303, Max Size 4 MB
-
8/6/2019 14806 Database Mail
18/31
Managing Profiles and Accounts
sysmail_add_profile_sp:-This stored procedure
allows you to create a new profile to be used by
the Database Mail service.
sysmail_add_profile_sp [ @profile_name = ]
name , [ @description = ] desc,
[ @profile_id = ]profile_id OUTPUT
-
8/6/2019 14806 Database Mail
19/31
Cont
DECLARE @profileID INT ;
EXECUTE msdb.dbo.sysmail_add_profile_sp
@profile_name = HumanResourcesMail, @description = Mail Profile for the Human
Resources team.,
@profile_id = @profileID OUTPUT ;
SELECT @profileID ;
-
8/6/2019 14806 Database Mail
20/31
Cont
The sysmail_help_profile_sp stored procedure will
return information about the profiles created on the
SQL Server.
EXEC msdb.dbo.sysmail_help_profile_sp
@profile_id=2
SELECT * FROM msdb.dbo.sysmail_profile
-
8/6/2019 14806 Database Mail
21/31
-
8/6/2019 14806 Database Mail
22/31
Cont..
EXECUTE msdb.dbo.sysmail_help_account_sp
EXECUTE msdb.dbo.sysmail_help_account_sp
@account_id=2
SELECT *FROM msdb.dbo.sysmail_account
-
8/6/2019 14806 Database Mail
23/31
sysmail_add_profileaccount_sp
youve created a new profile and a new account.
Now you can associate that account with that
profile.
Accounts can be associated with more than one
profile, and each profile can be configured to use
more that one account.
To create the mapping, you can use thesysmail_add_profileaccount_sp stored procedure.
-
8/6/2019 14806 Database Mail
24/31
Cont..
EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
@profile_id = 2,
@account_name = MyAccount,
@sequence_number = 1;
EXECUTE
msdb.dbo.sysmail_help_profileaccount_sp
SELECT * FROM msdb.dbo.sysmail_profileaccount
-
8/6/2019 14806 Database Mail
25/31
sysmail_update_profile_sp
EXECUTE msdb.dbo.sysmail_update_profile_sp
@profile_id = 2,
@profile_name = HRMail,
@description = Human Resources Mail Profile;
EXECUTE msdb.dbo.sysmail_help_profile_sp;
-
8/6/2019 14806 Database Mail
26/31
sysmail_update_account_sp EXECUTE msdb.dbo.sysmail_update_account_sp @account_id = 1,
@account_name = SalesMail,
@display_name = Microsoft SQL Server - Aughtfive,
@replyto_address = [email protected],
@description = Sales Mail Account,
@mailserver_name = aughtfive,
@mailserver_type = SMTP,
@port = 25,
@username = NULL,
@password = NULL,
@use_default_credentials = 1,
@enable_ssl = 0;
EXECUTE msdb.dbo.sysmail_help_account_sp
-
8/6/2019 14806 Database Mail
27/31
sysmail_update_profileaccount_sp
If you want to change the sequence in which the
accounts will be used within a profile,
you can use the sysmail_update_profileaccount_sp
stored procedure.
-
8/6/2019 14806 Database Mail
28/31
sysmail_add_principalprofile_sp
This stored procedure is used to control access to a
mail profile. In order for the profile to be
accessible,
the profile will be made available to specificdatabase principals within the msdb database.
EXECUTE
msdb.dbo.sysmail_help_principalprofile_sp @principal_name = public;
-
8/6/2019 14806 Database Mail
29/31
Stored Procedures
sysmail_update_principalprofile_sp
sysmail_delete_principalprofile_sp
sysmail_delete_profileaccount_sp
sysmail_delete_account_sp
sysmail_delete_profile_sp
-
8/6/2019 14806 Database Mail
30/31
Guidelines for Deleting Mail Objects
Deleting a profile/account mapping is non-destructive. Itsimply removes the relationship
between the profile and account. If necessary, this can beeasily re-created. If another account is properly configuredwithin the profile, this should not disrupt operations.
Deleting an account removes its availability in all profiles. Ifthe profiles already have another valid account configured,
then you shouldnt notice any problems. If you are deletingan account that is the only account in one or more profiles,those profiles will not be able to send mail.
-
8/6/2019 14806 Database Mail
31/31
Cont..
Deleting a profile removes a list of configured
accounts, not the accounts themselves. If,
however,your application is configured to use a mail
profile youve recently deleted, once again,yourSQL Server will be unable to send messages.