Database Mail. What is Database Mail? In a short answer, Database Mail is a feature of SQL Server which let Database sends Mail or SMS to anybody after.

Slides:



Advertisements
Similar presentations
SSRS 2008 Architecture Improvements Scale-out SSRS 2008 Report Engine Scalability Improvements.
Advertisements

GP2013 (R2) New features in GP2013 (R2). New Ribbon for windows Edit List is the Print button on the right without the paper background Action pane can.
Week 6: Chapter 6 Agenda Automation of SQL Server tasks using: SQL Server Agent Scheduling Scripting Technologies.
Maintaining and Automating SQL Server
SQL Server Agent Keith Binford. SQL Server Agent SQL Server Agent is a Windows service that can execute and schedule tasks and jobs.
Lesson 17: Configuring Security Policies
Advanced Workgroup System. Printer Admin Utility Monitors printers over IP networks Views Sharp and non-Sharp SNMP Devices Provided Standard with Sharp.
Installation and Deployment in Microsoft Dynamics CRM 4.0
14.1 © 2004 Pearson Education, Inc. Exam Planning, Implementing, and Maintaining a Microsoft Windows Server 2003 Active Directory Infrastructure.
70-290: MCSE Guide to Managing a Microsoft Windows Server 2003 Environment Chapter 12: Managing and Implementing Backups and Disaster Recovery.
Hands-On Microsoft Windows Server 2003 Administration Chapter 5 Administering File Resources.
70-290: MCSE Guide to Managing a Microsoft Windows Server 2003 Environment Chapter 8: Implementing and Managing Printers.
Maintaining and Updating Windows Server 2008
Check Disk. Disk Defragmenter Using Disk Defragmenter Effectively Run Disk Defragmenter when the computer will receive the least usage. Educate users.
Using the Windows Event Viewer and Task Scheduler Chapter 5.
AGENDA Tools used in SQL Server 2000 Graphical BOL Enterprise Manager Service Manager CLI Query Analyzer OSQL BCP.
Managing and Monitoring SQL Server 2005 Shankar Pal Program Manager SQL Server, Redmond.
Service Broker Lesson 11. Skills Matrix Service Broker Service Broker, provides a solution to common problems with message delivery and consistency that.
1 Chapter Overview Transferring and Transforming Data Introducing Microsoft Data Transformation Services (DTS) Transferring and Transforming Data with.
Slide 1 of 9 Presenting 24x7 Scheduler The art of computer automation Press PageDown key or click to advance.
Overview SAP Basis Functions. SAP Technical Overview Learning Objectives What the Basis system is How does SAP handle a transaction request Differentiating.
1 © 2001, Cisco Systems, Inc. All rights reserved. Voice Connector Features Voic Interoperability – 4.0(5) Voice Connector features Rahul Singh.
Today’s Agenda Chapter 12 Admin Tasks Chapter 13 Automating Admin Tasks.
Module 13 Automating SQL Server 2008 R2 Management.
Overview What is SQL Server? Creating databases Administration Security Backup.
Managing DHCP. 2 DHCP Overview Is a protocol that allows client computers to automatically receive an IP address and TCP/IP settings from a Server Reduces.
Module 8: Managing Client Configuration and Connectivity.
Copyright ®xSpring Pte Ltd, All rights reserved Versions DateVersionDescriptionAuthor May First version. Modified from Enterprise edition.NBL.
70-290: MCSE Guide to Managing a Microsoft Windows Server 2003 Environment, Enhanced Chapter 12: Managing and Implementing Backups and Disaster Recovery.
Maintaining a Mirrored Database Tips and Tricks by Paul G. Hiles.
User Manager Pro Suite Taking Control of Your Systems Joe Vachon Sales Engineer November 8, 2007.
Copyright © 2007, Oracle. All rights reserved. Managing Concurrent Requests.
Module 7: Fundamentals of Administering Windows Server 2008.
Module 9 Configuring Messaging Policy and Compliance.
Module 10: Monitoring ISA Server Overview Monitoring Overview Configuring Alerts Configuring Session Monitoring Configuring Logging Configuring.
1 What’s the difference between DocuShare 3.1 and 4.0?
MCSE Guide to Microsoft Exchange Server 2003 Administration Chapter Two Installing and Configuring Exchange Server 2003.
Learningcomputer.com SQL Server 2008 – Administration, Maintenance and Job Automation.
IT 456 Seminar 5 Dr Jeffrey A Robinson. Overview of Course Week 1 – Introduction Week 2 – Installation of SQL and management Tools Week 3 - Creating and.
Module 9 Configuring Messaging Policy and Compliance.
Module 1: Exploring Replication. Overview Understanding SQL Server Replication Setting Up Replication Understanding Agents in Replication Securing Replication.
Microsoft Office Outlook 2013 Microsoft Office Outlook 2013 Courseware # 3252 Lesson 6: Organizing Information.
1 Chapter Overview Preparing to Upgrade Performing a Version Upgrade from Microsoft SQL Server 7.0 Performing an Online Database Upgrade from SQL Server.
1 Chapter Overview Performing Configuration Tasks Setting Up Additional Features Performing Maintenance Tasks.
Module 15 Monitoring SQL Server 2008 R2 with Alerts and Notifications.
Systems Management Server 2.0: Backup and Recovery Overview SMS Recovery Web Site location: Updated.
Module 3 Managing Recipient Objects. Module Overview Managing Mailboxes Managing Other Recipients Configuring Address Policies Configuring Address.
Module 7 Planning and Deploying Messaging Compliance.
1 Chapter Overview Defining Operators Creating Jobs Configuring Alerts Creating a Database Maintenance Plan Creating Multiserver Jobs.
Cluster Consistency Monitor. Why use a cluster consistency monitoring tool? A Cluster is by definition a setup of configurations to maintain the operation.
Configuring and Troubleshooting Identity and Access Solutions with Windows Server® 2008 Active Directory®
Internal and Confidential Cognos CoE COGNOS 8 – Event Studio.
MCSE Guide to Microsoft Exchange Server 2003 Administration Chapter Three Managing Recipients.
SQL SERVER 2008 Installation Guide A Step by Step Guide Prepared by Hassan Tariq.
MCSE Guide to Microsoft Exchange Server 2003 Administration Chapter One Introduction to Exchange Server 2003.
Maintenance Practices. Goal  Automate the necessary DBA chores to put organizations on the path of having healthier, consistent and more trustworthy.
30 Copyright © 2009, Oracle. All rights reserved. Using Oracle Business Intelligence Delivers.
Hands-On Microsoft Windows Server 2008 Chapter 5 Configuring Windows Server 2008 Printing.
Log Shipping, Mirroring, Replication and Clustering Which should I use? That depends on a few questions we must ask the user. We will go over these questions.
Introduction to SQL Server  Working with MS SQL Server and SQL Server Management Studio.
Making Sense of Service Broker Inside the Black Box.
SQL Database Management
Project Management: Messages
Essentials of UrbanCode Deploy v6.1 QQ147
(Includes setup) FAQ ON DOCUMENTS (Includes setup)
Making Sense of Service Broker
Limiting SQL Server Exposure
Ch 10. Maintaining and Automating SQL Server
Presentation transcript:

Database Mail

What is Database Mail? In a short answer, Database Mail is a feature of SQL Server which let Database sends Mail or SMS to anybody after a transaction

SQL Server has a functionality to do such a thing. In fact whenever a transaction commits or Rollbacks after that SQL Server can send SMS or to anybody with any limitation.

Database Mail run outside of SQL Server so it is not pressure on your SQL Server Engine. It also is support clustered environment and can use SMTP Servers. On the other hand it sends mails asynchronously with Service broker so there will be no waste time and it has some security maintenance which let you filter messages

The best example to send SMS is after a Backup procedure it doesn’t matter that it is commit or rollback, you will receive SMS (mail) after the procedure and you can remotely run the backup procedure after a rollback. It is very good for DBAs

When SQL Server 2005 was released, the added functionality of Database Mail came with it, giving us the ability to use SMTP to send from SQL Server instances. This was a huge leap forward from SQL Server 2000 SQL Mail, in that you no longer needed to set-up a mail client first (such as Outlook) to send s.

Reliability  No Microsoft Outlook or Extended MAPI requirement. Database Mail uses SMTP to send mail.  Process isolation. To minimize the impact on SQL Server, the component that delivers runs outside of SQL Server, in a separate process. SQL Server will continue to queue messages even if the external process stops or fails. The queued messages will be sent once the outside process or SMTP server comes online.  Failover accounts. A Database Mail profile allows you to specify more than one SMTP server. Should an SMTP server be unavailable, mail can still be delivered to another SMTP server.  Cluster support. Database Mail is cluster-aware and is fully supported on a cluster.

Scalability  Background delivery. Database Mail provides background, or asynchronous, delivery. When you call sp_send_dbmail to send a message, Database Mail adds a request to a Service Broker queue. The stored procedure returns immediately. The external component receives the request and delivers the .  Multiple profiles. Database Mail allows you to create multiple profiles within a SQL Server instance. Optionally, you can choose the profile that Database Mail uses when you send a message.  Multiple accounts. Each profile can contain multiple failover accounts. You can configure different profiles with different accounts to distribute across multiple servers.  64-bit compatibility. Database Mail is fully supported on 64-bit installations of SQL Server.

Security  Off by default. To reduce the surface area of SQL Server, Database Mail stored procedures are disabled by default.  To send Database Mail, you must be a member of the Databas UserRole database role in the msdb database.  Profile security:  Database Mail enforces security for mail profiles.  You choose the msdb database users or groups that have access to a Database Mail profile.  You can grant access to either specific users, or all users in msdb. A private profile restricts access to a specified list of users. A public profile is available to all users in a database.

Security  Attachment size governor.  Database Mail enforces a configurable limit on the attachment file size. You can change this limit by using the sysmail_configure_sp stored procedure. sysmail_configure_sp  Prohibited file extensions.  Database Mail maintains a list of prohibited file extensions. Users cannot attach files with an extension that appears in the list. You can change this list by using sysmail_configure_sp.  Database Mail runs under the SQL Server Engine service account. To attach a file from a folder to an , the SQL Server engine account should have permissions to access the folder with the file.

Supportability  Integrated configuration.  Database Mail maintains the information for accounts within SQL Server Database Engine. There is no need to manage a mail profile in an external client application.  Database Mail Configuration Wizard provides a convenient interface for configuring Database Mail. You can also create and maintain Database Mail configurations using Transact-SQL.

With above information you can guess that what the Database Mail requirements are.  SQL Server (2005 – 2008) – SQL Express don’t have Database Mail.  Enabling Service Broker  Enabling Database Mail  A Mail Server (Usually Exchange Server) to send Mails.  Configuring Database Mail to use it.

How to Configure Database Mail Database Mail is disabled by default and you have to enable it. To enabling it you have three options.  First one is to use Database Mail Configuration Wizard.  The Second solution to configure Database Mail, is to use Store procedures.  The third solution is using the Surface Area Configuration facet of Policy-Based Management.

Configure Database Mail SQL Server 2008 

Enabling and configuring Database Mail in SQL Server using T-SQL  The second method is to use Transact SQL (T-SQL) and stored procedures to enable and configure Database Mail, which is much quicker, and less prone to human error, after the initial run has been tested and confirmed as working.  databas -in-sql-server-using-t-sql/ databas -in-sql-server-using-t-sql/

Enabling and configuring Database Mail in SQL Server using T-SQL  This walk through will execute a number of stored procedures to accomplish the following tasks:  Enable the Database Mail feature  Create a profile for Database Mail  Create an account for use with the profile  Send a test to the DBAs address  Enable the SQL Server Agent to use Database Mail  Add the ‘DBAs’ as an operator for notifications  Before running any of scripts below, I would take a backup of your system databases (master, msdb), and ensure you have sysadmin rights.

Enable the Database Mail XPs:  USE master  GO  sp_configure 'show advanced options',1  GO  RECONFIGURE WITH OVERRIDE  GO  sp_configure 'Database Mail XPs',1  GO  RECONFIGURE  GO

Create a new mail profile:  USE msdb  GO  EXECUTE msdb.dbo.sysmail_add_profile_sp = 'admin', = 'Profile for sending Automated DBA Notificati ons'  GO

Create an account for the notifications (changing the address, mail server, port as appropriate to your environment):  EXECUTE msdb.dbo.sysmail_add_account_sp = 'SQLAlerts', = 'Account for Automated DBA Notifications', = = 'SQL Alerts', = 'smtp.example.com', = 25  GO

Add the account to the profile:  EXECUTE msdb.dbo.sysmail_add_profileaccount_sp = 'admin', = 'SQLAlerts', = 1  GO

Enable the SQL Server Agent to use Database Mail profile by updating the registry settings:  USE msdb  GO  EXEC master.dbo.xp_instance_regwrite  N'HKEY_LOCAL_MACHINE',  N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent',  N'UseDatabas ',  N'REG_DWORD', 1  EXEC master.dbo.xp_instance_regwrite  N'HKEY_LOCAL_MACHINE',  N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent',  N'Databas Profile',  N'REG_SZ',  N'admin‘

NOTE: (0 row(s) affected) is normal here

Restart the SQL Server Agent:  At this point, the SQL Server Agent needs to be restarted. If it isn’t, the Database Mail configuration changes will not be picked up, and the Database Mail process will not start / function correctly.  If Database Mail is being configured on a SQL Server cluster, you’ll need to perform this using the Cluster Administrator tool by selecting the appropriate cluster group, then restarting the SQL Server Agent resource for the appropriate instance:  Windows Server 2003: C:\WINDOWS\Cluster\CluAdmin.exe  Windows Server 2008: C:\Windows\System32\Cluadmin.msc

Once the SQL Server Agent has been restarted, try sending an to test the configuration is working as expected:  EXECUTE msdb.dbo.sp_send_dbmail = 'admin', = = 'Test Message generated from SQL Server Database Mail', = 'This is a test message from SQL Server Database Mai l'  GO

Finally, setup an operator called ‘DBAs’ for the job notifications (24×7 schedule in this case) for the address you supplied earlier:  EXEC   GO

To generate notifications when a job succeeds, fails, or completes, you can run a stored procedures like below on a job by job basis:  USE msdb  GO  EXEC databases - ba ckups.Subplan_1',  GO  NOTE: The notify_levels can be set to: 1 (job succeeds), 2 (job fails), or 3 (job completes)

To enable failure notifications for all jobs, run the following script, which will update the notifications jobs for you, and output the T-SQL that’s been executed for each job identified:  vel NVARCHAR(3000)   DECLARE job_operator_cursor CURSOR FOR  SELECT name, job_id, notify_level_ FROM msdb.dbo.sysjob s_view   OPEN job_operator_cursor  FETCH NEXT FROM @ NotifyLevel  WHILE = 0  BEGIN  IF NOT EXISTS(SELECT 1 FROM msdb.dbo.sysjobs_view WHERE noti fy_level_ = 2 and name

 BEGIN  PRINT ''  = 'EXEC msdb.dbo.sp_update_job obName+''',   EXEC  END  FETCH NEXT FROM @ NotifyLevel  END

 CLOSE job_operator_cursor  DEALLOCATE job_operator_cursor

Quick troubleshooting queries for Database Mail  Check to see if the service broker is enabled (should be 1):  SELECT is_broker_enabled FROM sys.databases WHERE name = 'msdb'  Check to see if Database Mail is started in the msdb database:  EXECUTE dbo.sysmail_help_status_sp  …and start Database Mail if necessary:  EXECUTE dbo.sysmail_start_sp

Quick troubleshooting queries for Database Mail  Check the status of the mail queue:  = 'Mail'  Check the Database Mail event logs:  SELECT * FROM sysmail_event_log  Check the mail queue for the status of all items (including sent mails):  SELECT * FROM sysmail_allitems

 Logging.  Database Mail logs activity to SQL Server, the Microsoft Windows application event log, and to tables in the msdb database.  Auditing.  Database Mail keeps copies of messages and attachments sent in the msdb database. You can easily audit Database Mail usage and review the retained messages.  Support for HTML.  Database Mail allows you to send formatted as HTML.

GO HOME