Questions tagged [sp-send-dbmail]

`sp-send-dbmail` is a built-in stored procedure available in SQL Server since 2005, which allows one to send e-mails using the SQL service, for alerting a DBA when a problem is detected or limited reporting.

This procedure allows one to send an e-mail directly from SQL, including an optional query. It is well-suited for simple alerts and debugging, and in a pinch can be used to distribute reports, though it supports only a limited amount of formatting.

To use this sproc, one must first configure a Database Mail account and profile. This is available from within SQL Studio under [Server Name] > Management > Database Mail > right-click > Configure Database Mail.

Here's a code sample for a very simple message:

EXEC msdb..sp_send_dbmail
    @profile_name = 'My Profile',
    @recipients = 'dba@widgetcorp.com',
    @from_address = 'database_alerts@widgetcorp.com',
    @subject = 'Error Detected',
    @body = 'A problem has been found, best get on it.'

sp-send-dbmail has a large number of parameters, well-documented on MSDN:

234 questions
0
votes
1 answer

Alternate way to using cursor/loop in SQL

I want to see if there is any way to do what I'm trying to do without using cursors, or any looping logic. I have these 2 tables. There is a ONE-MANY relationship between FileRunData and Invoice, and they're linked by RunId/FileRunId. CREATE TABLE…
karan k
  • 947
  • 2
  • 21
  • 45
0
votes
1 answer

Sending Email in SQL Server 2008 R2

I am tasked with a feature to send e-mail reminders to employees in my company if they haven't completed an attestation form via an intranet Web application. I was thinking of writing a stored procedure that gets called in a nightly database job…
Yoav
  • 150
  • 1
  • 2
  • 15
0
votes
0 answers

Embed images from a database table in an email using sp_send_dbmail (SQL Server 2008 R2)

I currently have a SQL Server 2005 database that sends HTML emails to various users, and I take advantage of the @file_attachments parameter to embed images in the email. I have the image files on the SQL Server itself, so the parameter refer to the…
Jim
  • 55
  • 2
  • 10
0
votes
1 answer

Need to pass a parameter within a stored procedure to sp_send_dbmail @query

I have a stored procedure that executes a query and then calls dbmail. The mail message includes the results of the query that is executed. I want to pass a parameter/variable to the query in both places: the stored procedure and the @query in…
0
votes
0 answers

SQL 2008 R2: DBMail status 'sent', mail sometimes not received depending on the value of the subject

I encountered the strangest bug I have ever seen... I have a stored procedure that sends an email. The DB status (msdb.dbo.sysmail_mailitems) always sais 'sent' and the send_status is always 1 (success). However, the mails don't arrive always. I…
Jan Solo
  • 183
  • 1
  • 8
  • 19
0
votes
1 answer

How do I use sp_send_dbmail to send the content of a VARBINARY column?

I have some files stored in a SQL Server 2005 table in a VARBINARY(MAX) column. I need to email these files to users on a schedule, and though I can write a C# service to extract and send the email sp_send_dbmail would seem to be perfect for my…
None
0
votes
2 answers

multiple emails sent by sp_db_sendmail when run as SSIS package

I've a procedure which generates a tab delimited text file and also sends an email with a list of students as attachment using msdb.dbo.sp_send_dbmail. When I execute the procedure thoruhg SQL server management studio, it sends only one email. But…
Anj
  • 1
  • 1
0
votes
1 answer

sp_send_dbmail sends empty results

When using sp_send_dbmail like this : EXEC msdb.dbo.sp_send_dbmail @profile_name = 'MY_PROFILE' ,@recipients = 'MY_EMAIL_ADDRESS' ,@query = 'SELECT TOP 50 FIELD1, FIELD2, FIELD3 FROM TABLE1' ,@subject = 'MY_SUBJECT' ,@body =…
Shadowxvii
  • 1,080
  • 2
  • 12
  • 31
0
votes
1 answer

Using cursor in dbMail in sql server 2008

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…
user2363530
  • 25
  • 1
  • 9
0
votes
0 answers

SQL server 2008 DB mail sending Fail Issue

I have Created Profile and Account in My server. While sending a test mail it Throws an error: The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 3 (2013-05-30T19:07:28). Exception…
0
votes
1 answer

SQL Stored Procedure Send mail with attachement

i have a stored procedure that sends an email with an attachment, one of the developers decided to drop the lookup table with the file paths in, I've recreated the table but cant remember how the string needs to be for the file path and name to be…
GPH
  • 1,817
  • 3
  • 29
  • 50
0
votes
1 answer

SQL Server : sp_send_dbmail never queues email when calling stored procedure

I've got a SQL job that is set up to run sp_send_dbmail and attach the results of a stored procedure as a csv file to the email. This job was running up until a week and a half ago. Full disclosure: I made a change to the stored procedure around…
morris295
  • 517
  • 1
  • 7
  • 21
0
votes
2 answers

sp_send_dbmail not sending multiple rows from the query in the message

I am switching some code from xp_sendmail, but am not getting the results I expect from sp_send_dbmail. The query I am trying is below, and the message body in the email only contains one line: My first header entry Did Microsoft really design…
0
votes
1 answer

T-SQL Convert multiples rows into short SMS text string/message

I'm trying to create a short SMS message and a full formatted email from the same data. How can I convert 2 rows from at able into a SQL string for purposes of the text email. I have only 4 rows in my table, and I assign them a rating of "Good" or…
NealWalters
  • 17,197
  • 42
  • 141
  • 251
0
votes
1 answer

dbo.sp_send_dbmail and HTML when one email SPROC calls existing SPROC

I want to build HTML and use sp_send_dbmail to send it. Option C on this page explain how to do that. http://msdn.microsoft.com/en-us/library/ms190307.aspx But here's my catch. I have created a stored proc called AbcStats. Quite often, I go to…
NealWalters
  • 17,197
  • 42
  • 141
  • 251
1 2 3
15
16