1

I'm trying to send an email through SQL Server. The sp_send_dbmail has a parameter to specify the path of a file to send as an attachment. It works perfectly when the file is in the same server where SQL Server is hosted. However, I need to send a file that is stored on another server or computer in the same network.

How can I specify the path for such file?

Edit: I see no errors in the server agent logs nor dbmail. I ran this query: Select * FROM sys.dm_server_services and gave the account under the service_account column full control of the file in the remote server.

This is how I'm calling the sp:

EXEC msdb.dbo.sp_send_dbmail
    @profile_name = 'Profile',
    @recipients = 'email@email.com',
    @subject = 'Testing Attachments',
    @file_attachments = '\\servername\c$\Temp\OutputReport.pdf'

Error: Msg 22051, Level 16, State 1, Line 0

Attachment file '\\servername\c$\Temp\OutputReport.pdf' is invalid.

  • A few things to consider for any file/folder access. Does the SQL Server service account have access to this remote file? How are you specifying the path? Are you using the FQN of the file? There should be an error and that would be a great place to start troubleshooting. Look at your agent logs or dbmail logs. – samosql Jun 20 '18 at 22:40
  • You need to create a share on the another server. UNC paths are like \\servername\sharename\filepath – CR241 Jun 20 '18 at 23:06
  • @samosql Thanks for the help. I edited the post. I don't see what I am missing. – Willy Jun 22 '18 at 13:25
  • @CR241 The file is already saved on another computer in the same domain and I am using the UNC path. I edited the post. Thanks – Willy Jun 22 '18 at 13:26
  • Are you 100% sure that is the name of the remote file? Can you actually bring up a Windows Explorer window and paste \\servername\c$\Temp\OutputReport.pdf into it and retrieve that file? I purposely tried to attach a remote file using @file_attachments with a letter missing from the remote file name and received the same error you did. When I specified the correct name of the remote file, the email successfully included the attachement. – Scott Hodgin Jun 22 '18 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.