Suche…


Syntax

  • sp_send_dbmail [[@profile_name =] 'profilname'] [, [@recipients =] 'Empfänger [; ... n] '] [, [@copy_recipients =]' copy_recipient [; ... n] '] [, [@blind_copy_recipients =]' blind_copy_recipient [; ... n] '] [, [@von_Adresse =]' von_Adresse '] [, [@reply_to =]' reply_to '] [, [@subject =]' subject '] [, [@body =]' body ' ] [, [@body_format =] 'body_format'] [, [@importance =] 'Wichtigkeit'] [, [@sensitivity =] 'Sensitivität'] [, [@file_attachments =] 'Anhang [; ... n] '] [, [@query =]' query '] [, [@execute_query_database =]' execute_query_database '] [, [@attach_query_result_as_file =] attach_query_result_as_file] [, [@query_attachment_filename =] query_attaching_date @query_result_header =] query_result_header] [, [@query_result_width =] query_result_width] [, [@query_result_separator =] 'query_result_separator'] [, [@clude_query_output =] exclude_query_output] [, [@endend_query_output]] query_no_truncate] [, [@query_result_no_padding =] @query_result_no_padding] [, [@mailitem_id =] mailitem_id] [OUTPUT]

Senden Sie eine einfache E-Mail

Dieser Code sendet eine einfache Text-E-Mail an Empfä[email protected]

EXEC msdb.dbo.sp_send_dbmail  
    @profile_name = 'The Profile Name',  
    @recipients = '[email protected]',  
    @body = 'This is a simple email sent from SQL Server.',  
    @subject = 'Simple email' 

Ergebnisse einer Abfrage senden

Dadurch werden die Ergebnisse der Abfrage SELECT * FROM Users und an [email protected]

EXEC msdb.dbo.sp_send_dbmail  
    @profile_name = 'The Profile Name',  
    @recipients = '[email protected]',  
    @query = 'SELECT * FROM Users',  
    @subject = 'List of users',  
    @attach_query_result_as_file = 1; 

HTML-E-Mail senden

HTML-Inhalte müssen an sp_send_dbmail

SQL Server 2012
DECLARE @html VARCHAR(MAX);
SET @html = CONCAT
(
    '<html><body>',
    '<h1>Some Header Text</h1>',
    '<p>Some paragraph text</p>',
    '</body></html>'
)
SQL Server 2012
DECLARE @html VARCHAR(MAX);
SET @html =
    '<html><body>' +
    '<h1>Some Header Text</h1>' +
    '<p>Some paragraph text</p>' +
    '</body></html>';

Verwenden Sie dann die Variable @html mit dem @body argument . Die HTML-Zeichenfolge kann auch direkt an @body , obwohl der Code dadurch möglicherweise schwieriger zu lesen ist.

EXEC msdb.dbo.sp_send_dbmail 
    @recipients='[email protected]',  
    @subject = 'Some HTML content',  
    @body = @html,  
    @body_format = 'HTML';  


Modified text is an extract of the original Stack Overflow Documentation
Lizenziert unter CC BY-SA 3.0
Nicht angeschlossen an Stack Overflow