sp-send-dbmail

sp_send_dbmail attach files stored as varbinary in database

╄→гoц情女王★ 提交于 2019-12-01 17:44:58
问题 I have a two part question relating to sending query results as attachments using sp_send_dbmail. Problem 1: Only basic .txt files will open. Any other format like .pdf or .jpg are corrupted. Problem 2: When attempting to send multiple attachments, I receive one file with all file names glued together. I'm running SQL Server 2005 and I have a table storing uploaded documents: CREATE TABLE [dbo].[EmailAttachment]( [EmailAttachmentID] [int] IDENTITY(1,1) NOT NULL, [MassEmailID] [int] NULL, --

Generic failure using sp_send_dbmail in SQL Server 2014

为君一笑 提交于 2019-12-01 07:03:18
I'm trying to use sp_send_dbmail to send the results of a query through a SQLAgent job in SQL Server 2014. I believe I have my DBMail profile set up properly but when running this: exec msdb.dbo.sp_send_dbmail @profile = 'TestProfile', @recipients = 'testmail@gmail.com', @subject = 'Test', @query = 'SELECT id FROM TestTable', @attach_query_result_as_file = 1, @query_attachment_filename = 'TestValues.txt' I get the following error message: Failed to initialize sqlcmd library with error number -2147467259. Googling this error message didn't turn up anything useful, likely due to the generic

sp_send_dbmail - formatting row in table as red for an alert

痞子三分冷 提交于 2019-12-01 00:50:30
I'm using something similar to example C on this MSDN page: http://msdn.microsoft.com/en-us/library/ms190307.aspx DECLARE @tableHTML NVARCHAR(MAX) ; SET @tableHTML = N'<H1>Work Order Report</H1>' + N'<table border="1">' + N'<tr><th>Work Order ID</th><th>Product ID</th>' + N'<th>Name</th><th>Order Qty</th><th>Due Date</th>' + N'<th>Expected Revenue</th></tr>' + CAST ( ( SELECT td = wo.WorkOrderID, '', td = p.ProductID, '', td = p.Name, '', td = wo.OrderQty, '', td = wo.DueDate, '', td = (p.ListPrice - p.StandardCost) * wo.OrderQty FROM AdventureWorks.Production.WorkOrder as wo JOIN

sp_send_dbmail - formatting row in table as red for an alert

半腔热情 提交于 2019-11-30 19:58:15
问题 I'm using something similar to example C on this MSDN page: http://msdn.microsoft.com/en-us/library/ms190307.aspx DECLARE @tableHTML NVARCHAR(MAX) ; SET @tableHTML = N'<H1>Work Order Report</H1>' + N'<table border="1">' + N'<tr><th>Work Order ID</th><th>Product ID</th>' + N'<th>Name</th><th>Order Qty</th><th>Due Date</th>' + N'<th>Expected Revenue</th></tr>' + CAST ( ( SELECT td = wo.WorkOrderID, '', td = p.ProductID, '', td = p.Name, '', td = wo.OrderQty, '', td = wo.DueDate, '', td = (p

sp_send_dbmail will not send query results

感情迁移 提交于 2019-11-30 13:51:46
I've tried every avenue on every damn forum suggested, but to no avail! Need to send results of SQLPERF(logspace), that have been stored in a table, via sp_send_dbmail to recipient. Step 2 of job is where failure occurs. Please help! EXEC msdb.dbo.sp_send_dbmail @profile_name= 'MyDBA', @recipients= 'Mack@mydba.co.za', @subject='Log Warning', @query='SELECT * from #TempForLogSpace WHERE LogSpaceUsed >80 You can't query from a temp table using database mail. The session that you used to create the temp table (step 1 of your job I assume) has been closed and a new session started when step 2

sp_send_dbmail executed from job fails with query result attached as file

耗尽温柔 提交于 2019-11-30 07:24:27
问题 I have faced with the following issue: when trying to send email with results of query attached as file, using sp_send_dbmail via executing ordinary query everything seems to be working OK. But if add the same code into JobStep and run the job, it fails. Error in job history says Error formatting query, probably invalid parameters [SQLSTATE 42000] (Error 22050). The step failed. But when I comment out parameter that refers to file attaching it starts working correctly again. exec msdb.dbo.sp

sp_send_dbmail will not send query results

对着背影说爱祢 提交于 2019-11-29 19:48:34
问题 I've tried every avenue on every damn forum suggested, but to no avail! Need to send results of SQLPERF(logspace), that have been stored in a table, via sp_send_dbmail to recipient. Step 2 of job is where failure occurs. Please help! EXEC msdb.dbo.sp_send_dbmail @profile_name= 'MyDBA', @recipients= 'Mack@mydba.co.za', @subject='Log Warning', @query='SELECT * from #TempForLogSpace WHERE LogSpaceUsed >80 回答1: You can't query from a temp table using database mail. The session that you used to

Using cursor in dbMail in sql server 2008

时间秒杀一切 提交于 2019-11-29 17:47:40
I am trying to send remittance info to our customers with check# and amount on the check. I am unable to send one email per customer with check num and amount and remittance info. Right now email gets generated but it is only picking one customer and sending emails equal to num of records which get pulled. Please have a look at my query below, probably I am messing up in the cursor part. New code Declare @body nvarchar(max) declare @docnum nvarchar(50) declare @numatcard nvarchar(50) declare @checknum nvarchar(50) declare @checkAmt nvarchar(100) declare @EMaIL nvarchar(200) declare @Date

sp_send_dbmail executed from job fails with query result attached as file

陌路散爱 提交于 2019-11-29 03:13:35
I have faced with the following issue: when trying to send email with results of query attached as file, using sp_send_dbmail via executing ordinary query everything seems to be working OK. But if add the same code into JobStep and run the job, it fails. Error in job history says Error formatting query, probably invalid parameters [SQLSTATE 42000] (Error 22050). The step failed. But when I comment out parameter that refers to file attaching it starts working correctly again. exec msdb.dbo.sp_send_dbmail @profile_name = 'profile_name', @recipients = 'some@mail.com', @body = 'body', @subject =