This Stored procedure is used for sending mail from SQL server. This Procedure is available in msdb database.It is used to sends an email message to the specified person(receipients).The message may include a query result set,file attachment and query result as a file. When mail is successfully placed in the Databse Mail Queue ,sp_send_dbmail returns the mailitem_id of the message. Before use,Database Mail must be enabled using the Databse Mail Configuration.The Stored procedure sp_send_dbmail does not support mail message without no content, To send an email,you should specify at least one of body of the message,subject,Query,file attachment etc. otherwise return an error.
When no profile is specified,sp_send_dbmail uses a default profile, If the user sending the mail message has a private profile, The database Mial uses that profile.If the user has no profile sp-send_dbmailuses default public profile. If there is no prfile available in mail, sp_send_db_mail returns an error.
Execute permissions for sp_send_dbmail default to all members of the DatabaseMailUser databse role in msdb database. When the user sending the message does not have permission to use the profile for request, sp_send_dbmail returns an error and does not send the mail message. The mail message can be send Text or HTML format.
Syntax: ------
sp_send_dbmail [@profile_name =] 'profile_name', [@receipients =] 'receipient_name', [@copy_receipients=] 'copy_receipients', [@blind_copy_receipients =] 'blind_copy', [@subject =] 'subject', [@body=] 'body', [@body_format=] 'body format', [@importance =] 'importance', [@sensititvity=] 'sensitivity', [@file attachments] 'file_path', [@query=] 'sql query', [@execute_query_database=] 'execute', [@attach_query_result_as_file=] result as a file, [query_attachment_filename=] filename, [@query_result_header=] Result header, [@query_result_width=] width, [@query_result_separator=] esult as a separator', [exclude_query_output=] query_output, [@append_query_error =] append', [@query_no_truncate=] 'Query Truncate', [@mailitem_id=] mailitem_id [output]
Then exec sp_send_dbmail
We will get output through mail.
Regards, Kavitha Premkumar
|
No responses found. Be the first to respond and make money from revenue sharing program.
|