Is it possible to send email attachment using dbmail from cmd? I'm using a batch file to send email attachment using dbmail but getting an error. Here is my code: sqlcmd -q "EXEC msdb.dbo.sp_send_dbmail @profile_name = 'ProfileName', @
firstname.lastname@example.org', @subject='Test Attachment ', @body='Using dbmail to send attachment', @file_attachments='C:\document\example.txt'" the error message that i'm getting is incorrect syntax near 'exec msdb.dbo.sp_send dbmail @profile_name='auditProfile'
Yes, you should be able to send an attachment, as per the guidance:
http://msdn.microsoft.com/en-us/library/ms190307(v=sql.90).aspx (this is for SQL 2005). The only thing that I notice is the lack of '\\' in your attachment string. Probably should read: "@file_attachments = 'C:\\
DocumentExample.txt'" Everything else, at least to me, looks correct. Although it's quite possible you have that in there and the forum monster's took it as an escape character. ;-)
One thing that comes to my mind - you've shown the Query parameter above spread across multiple lines. Is that as it is in your script, or have you just formatted it for clarity? Something that might be worth doing, if you're having that sort of problem, is putting the whole of your SQL Query into a separate file, and sending that through to SQLCmd using the `-i` parameter.