In this article I will explain with an example, how to resolve the error while using the sp_send_dbmail Stored Procedure in SQL Server.
Attachment file D:\Files\Customers.csv is invalid.
This article is applicable to following SQL Server versions i.e. 2008, 2008R2, 2012, 2014, 2016, 2017, 2019 and 2022.
 
 

Error

The following error occurs while sending email with attachment from Folder (Directory) in SQL Server.
SQL Server sp_send_dbmail Error: attachment file is invalid
 
 

Cause

This error occurs because the sp_send_dbmail Stored Procedure is not able to access the file or the file is not present in the specified location.
 
 

Solutions

1. Make sure the file is present the specified path.
2. You are connected to a remote SQL Server Database Engine while the file is present in local machine. Thus, you need to copy the file to the machine where SQL Server is installed.