Microsoft SQL Server
DBMAIL
Zoeken…
Syntaxis
- sp_send_dbmail [[@profile_name =] 'profile_name'] [, [@recipients =] 'ontvangers [; ... n] '] [, [@copy_recipients =]' copy_recipient [; ... n] '] [, [@blind_copy_recipients =]' blind_copy_recipient [; ... n] '] [, [@from_address =]' from_address '] [, [@reply_to =]' reply_to '] [, [@subject =]' subject '] [, [@body =]' body ' ] [, [@body_format =] 'body_format'] [, [@importance =] 'belang'] [, [@sensitivity =] 'gevoeligheid'] [, [@file_attachments =] 'bijlage [; ... n] '] [, [@query =]' query '] [, [@execute_query_database =]' execute_query_database '] [, [@attach_query_result_as_file =] attach_query_result_as_file] [, [@query_attachment_filment [filementnaam] [bestand] @query_result_header =] query_result_header] [, [@query_result_width =] query_result_width] [, [@query_result_separator =] 'query_result_separator'] [, [@exclude_query_output =] exclude_query_appput_query_query_query_app ] query_no_truncate] [, [@query_result_no_padding =] @query_result_no_padding] [, [@mailitem_id =] mailitem_id] [OUTPUT]
Verzend eenvoudige e-mail
Deze code verzendt een eenvoudige e-mail met alleen tekst naar [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'
Resultaten van een zoekopdracht verzenden
Hiermee worden de resultaten van de zoekopdracht SELECT * FROM Users
en naar de [email protected]
gestuurd
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;
Stuur HTML email
HTML-inhoud moet worden doorgegeven aan 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>';
Gebruik vervolgens de variabele @html
met het @body argument
. De HTML-string kan ook rechtstreeks aan @body
worden doorgegeven, hoewel het moeilijker is om de code te lezen.
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
Licentie onder CC BY-SA 3.0
Niet aangesloten bij Stack Overflow