Step 2
The Configuration Component Database account can
be enabled by using the sysmail_add_account procedure.
In this article, we are going create the account, "MyMailAccount,"
using mail.optonline.net as the mail server and
makclaire@optimumonline.net as the e-mail
account.
Please execute the statement below.
EXECUTE msdb.dbo.sysmail_add_account_sp
@account_name = 'MyMailAccount',
@description = 'Mail account for Database Mail',
@email_address = 'makclaire@optonline.net',
@display_name = 'MyAccount',
@username='makclaire@optonline.net',
@password='abc123',
@mailserver_name = 'mail.optonline.net'
Step 3
The second sub component of the configuration
requires us to create a Mail profile.
In this article, we are going to create
"MyMailProfile" using the sysmail_add_profile procedure
to create a Database Mail profile.
Please execute the statement below.
EXECUTE msdb.dbo.sysmail_add_profile_sp
@profile_name = 'MyMailProfile',
@description = 'Profile used for database mail'
Step 4
Now execute the
sysmail_add_profileaccount
procedure, to add the Database Mail account
we created in step 2, to the Database Mail profile you
created in step 3.
Please execute the statement below.
EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
@profile_name = 'MyMailProfile',
@account_name = 'MyMailAccount',
@sequence_number = 1
Step 5
Use the sysmail_add_principalprofile procedure to grant the Database Mail profile access to the msdb
public database role and to make the profile the default Database
Mail profile.
Please execute the statement below.
EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
@profile_name = 'MyMailProfile',
@principal_name = 'public',
@is_default = 1 ;
Step 6
Now let us send a test email from SQL
Server.
Please execute the statement below.
declare @body1 varchar(100)
set @body1 = 'Server :'+@@servername+ ' My First Database Email '
EXEC msdb.dbo.sp_send_dbmail @recipients='mak_999@yahoo.com',
@subject = 'My Mail Test',
@body = @body1,
@body_format = 'HTML' ;
You
will get the message shown in Fig
1.1.