---
title: "Send Email with Excel / PDF Attachment in SQL Server"  
description: "you can send attachments using Database Mail via sp_send_dbmail. You have two main approaches"  
author: "Anubhav Sharma"  
published: 2026-04-29  
updated: 2026-04-29  
canonical: https://www.mindstick.com/articles/342102/send-email-with-excel-pdf-attachment-in-sql-server  
category: "database"  
tags: ["database", "sql server"]  
reading_time: 2 minutes  

---

# Send Email with Excel / PDF Attachment in SQL Server

In SQL Server, you can send attachments using **Database Mail** via `sp_send_dbmail`. You have two main approaches:

- **Attach an [existing file](https://www.mindstick.com/forum/33417/how-to-append-text-to-an-existing-file-in-java) (Excel/PDF)**
- **Generate query result as Excel (CSV/XLS)**

## 1. Attach Existing Excel / PDF File

If your file [already exists](https://www.mindstick.com/forum/34205/emailid-already-exists) on the server:

```plaintext
EXEC msdb.dbo.sp_send_dbmail
    @profile_name = 'MyMailProfile',
    @recipients = 'user@example.com',
    @subject = 'Report with Attachment',
    @body = 'Please find attached report.',
    @file_attachments = 'C:\Reports\DailyReport.xlsx;C:\Reports\Invoice.pdf';
```

## Key Points:

- Separate [multiple files](https://www.mindstick.com/forum/33990/attach-multiple-files-gridview-row-in-knockout-js) with `;`
- SQL Server service account must have access to the [file path](https://www.mindstick.com/forum/161592/how-do-you-validate-whether-a-given-path-is-a-valid-file-path-or-not)

## 2. Send Query Result as Excel File

SQL Server doesn’t create true `.xlsx`, but you can send data as **CSV/XLS format** (opens in Excel).

```plaintext
EXEC msdb.dbo.sp_send_dbmail
    @profile_name = 'MyMailProfile',
    @recipients = 'user@example.com',
    @subject = 'Excel Report',
    @query = 'SELECT * FROM Employees',
    @attach_query_result_as_file = 1,
    @query_attachment_filename = 'EmployeeReport.xls',
    @query_result_separator = ',',
    @query_result_no_padding = 1;
```

## 3. Send PDF (Generated via External Process)

SQL Server cannot directly generate PDFs. You must:

Generate PDF using:

- C# / ASP.NET
- SSRS ([SQL Server Reporting Services](https://www.mindstick.com/articles/1438/sql-server-reporting-services))
- PowerShell

Then send it:

```plaintext
EXEC msdb.dbo.sp_send_dbmail
    @profile_name = 'MyMailProfile',
    @recipients = 'user@example.com',
    @subject = 'PDF Report',
    @body = 'Attached PDF report.',
    @file_attachments = 'C:\Reports\Report.pdf';
```

## 4. Example: Daily Report with Excel Attachment

```plaintext
EXEC msdb.dbo.sp_send_dbmail
    @profile_name = 'MyMailProfile',
    @recipients = 'admin@company.com',
    @subject = 'Daily Sales Report',
    @query = '
        SELECT
            CAST(TransactionDate AS DATE) AS Date,
            COUNT(*) AS TotalOrders,
            SUM(Amount) AS TotalSales
        FROM Transactions
        WHERE CAST(TransactionDate AS DATE) = CAST(GETDATE()-1 AS DATE)
        GROUP BY CAST(TransactionDate AS DATE)
    ',
    @attach_query_result_as_file = 1,
    @query_attachment_filename = 'DailySales.xls';
```

## Common Issues

### File Not Attached

- [Check file](https://www.mindstick.com/forum/34415/how-to-check-file-exist-or-not-in-mvc-razor-view) path permissions
- Ensure SQL Server service account has access

### Large File Error

Increase Database Mail size limit:

```plaintext
EXEC msdb.dbo.sysmail_configure_sp
    'MaxFileSize', '10000000'; -- size in bytes
```

## Best Practices

- Store reports in a **dedicated folder**
- Use **scheduled jobs ([SQL Server Agent](https://answers.mindstick.com/qa/92510/what-is-the-sql-server-agent))**
- Avoid very large attachments
- Use **HTML email body** for better formatting

## Final Thoughts

SQL Server can easily send **Excel and PDF attachments**, but:

- Excel → can be generated directly (CSV/XLS)
- PDF → requires external generation

---

Original Source: https://www.mindstick.com/articles/342102/send-email-with-excel-pdf-attachment-in-sql-server

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
