---
title: "Configure Email in MS SQL Server (Database Mail)"  
description: "Sending emails directly from SQL Server is useful for alerts, reports, and automation. This is done using Database Mail, a built-in feature in SQL Ser"  
author: "Anubhav Sharma"  
published: 2026-04-29  
updated: 2026-04-29  
canonical: https://www.mindstick.com/blog/306895/configure-email-in-ms-sql-server-database-mail  
category: "database"  
tags: ["database", "sql server"]  
reading_time: 3 minutes  

---

# Configure Email in MS SQL Server (Database Mail)

[Sending emails](https://answers.mindstick.com/qa/109539/how-to-restore-outlook-no-longer-sending-emails) directly from SQL Server is useful for **alerts, reports, and automation**. This is done using **Database Mail**, a built-in feature in SQL Server.

## What is Database Mail?

**Database Mail** allows SQL Server to send emails using SMTP (like Gmail, Outlook, etc.) via [stored procedures](https://www.mindstick.com/forum/540/using-stored-procedures-with-entity-framework-in-an-asp-dot-net-application) such as `sp_send_dbmail`.

## Use Cases

- Send **daily reports** automatically
- Notify on **job failure/success**
- Alert on **critical errors**
- Send **[query results](https://www.mindstick.com/forum/158905/how-do-you-use-the-order-by-clause-to-sort-query-results-in-ascending-and-descending-order) via email**

## Step 1: Enable Database Mail

```plaintext
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;

EXEC sp_configure 'Database Mail XPs', 1;
RECONFIGURE;
```

## Step 2: Configure Database Mail (UI Method - Recommended)

- Open **SQL Server [Management Studio](https://www.mindstick.com/forum/159668/what-is-the-difference-between-sql-server-and-sql-management-studio) (SSMS)**
- Go to: **Management → Database Mail → Configure Database Mail**
- Select: **Set up Database Mail**

## Step 3: Create Mail Profile

- Profile Name: `MyMailProfile`
- Description: SQL Mail Profile

## Step 4: Add SMTP Account

Fill SMTP details:

- [Email Address](https://www.mindstick.com/forum/33871/how-to-validate-email-address-in-javascript): `yourmail@gmail.com`
- [Display Name](https://www.mindstick.com/forum/160249/what-is-the-role-of-the-display-data-annotation-to-display-name-for-a-model-property-in-dot-net-core): SQL Server
- [SMTP Server](https://answers.mindstick.com/qa/116515/top-smtp-server-providers-for-reliable-email-sending): `smtp.gmail.com`
- Port: `587`
- Enable SSL: true
- Username: your email
- Password: app password (recommended)

## Step 5: Test Email

```plaintext
EXEC msdb.dbo.sp_send_dbmail
    @profile_name = 'MyMailProfile',
    @recipients = 'test@example.com',
    @subject = 'Test Email',
    @body = 'Database Mail is working!';
```

## Step 6: Send Query Result via Email

```plaintext
EXEC msdb.dbo.sp_send_dbmail
    @profile_name = 'MyMailProfile',
    @recipients = 'admin@example.com',
    @subject = 'Daily Report',
    @query = 'SELECT TOP 10 * FROM Users',
    @attach_query_result_as_file = 1;
```

## Step 7: Use in SQL Server Agent Job

Go to **[SQL Server Agent](https://www.mindstick.com/interview/879/what-is-sql-server-agent) → Jobs**

Add step or notification:

- Send email on **success/failure**
- Attach logs or results

## Common Issues & Fixes

### 1. Email Not Sending

- Check SMTP credentials
- Enable "Less secure apps" or use app password

### 2. Queue Stuck

```plaintext
EXEC msdb.dbo.sysmail_start_sp;
```

### 3. Check Mail Logs

```plaintext
SELECT * FROM msdb.dbo.sysmail_allitems;
SELECT * FROM msdb.dbo.sysmail_event_log;
```

## Best Practices

- Use **app password** instead of main email password
- Restrict profile access (security)
- Monitor mail logs regularly
- Avoid sending large data directly

## Real-World Example

Send daily transaction report automatically:

```plaintext
EXEC msdb.dbo.sp_send_dbmail
    @profile_name = 'MyMailProfile',
    @recipients = 'admin@company.com',
    @subject = 'Daily Transaction Report',
    @query = 'SELECT * FROM DailyTransactionReport WHERE ReportDate = CAST(GETDATE()-1 AS DATE)';
```

## Final Thoughts

Configuring email in SQL Server using **Database Mail** is a powerful way to automate communication. Whether it’s alerts, reports, or monitoring—this feature can make your system **smarter and more responsive**.

## Read More:

[**Configure Database Mail in SQL Server**](https://www.sqlshack.com/configure-database-mail-sql-server/)

---

Original Source: https://www.mindstick.com/blog/306895/configure-email-in-ms-sql-server-database-mail

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
