Configure SQL Server DBMAIL using T-SQL

Configuring dBMail involves 3 main steps

Step 1: Creating Mail Profile

Step2: Creating Mail Account

Step3: Mapping Account to Profile.

Below script will let you do this 3 steps and configures your dBmail successfully.

Source


-    ENABLE SQL DBMAIL, if diabled

EXEC sys.sp_configure N'Database Mail XPs', N'1'

GO

 

RECONFIGURE

GO

 

-    Add Mail Profile

 

EXEC msdb.dbo.sysmail_add_profile_sp @profile_name=N'Profile Name'

GO

 

-    Set as Default Profile

 

EXEC msdb.dbo.sysmail_add_principalprofile_sp 

@profile_name=N'Profile Name',

@is_default =N'1'

GO

 

-    ADD MAIL ACCOUNT

 

EXEC msdb.dbo.sysmail_add_account_sp

 

   @account_name    = 'Account_Name',

   @email_address   = 'Email Address,EX:DBA@yourcompany.com',

   @display_name    = 'Account Name',

   @replyto_address = 'Email Address,EX:DBA@yourcompany.com',

   @mailserver_name = 'your SMTP Server',

   @mailserver_type = N'SMTP or if you use other mail protocol',

   @port                = 25,

   @use_default_credentials = 0,

   @enable_ssl = 0

GO

 

-    Mapping Account with Profile

 

EXEC  msdb.dbo.sysmail_add_profileaccount_sp   @profile_name=N'Profile Name', @account_name= N'Account Name',  @sequence_number=N'1'

GO

 
About these ads

Posted on December 11, 2012, in DBA SCRIPTS. Bookmark the permalink. Leave a comment.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: