首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

sp_send_dbmail :如果选择了特定变量,则发送电子邮件

sp_send_dbmail是SQL Server数据库中的一个存储过程,用于发送电子邮件。它可以通过配置数据库邮件来发送电子邮件,支持发送HTML格式的邮件和附件。

该存储过程的语法如下:

代码语言:txt
复制
sp_send_dbmail
    [ [ @profile_name = ] 'profile_name' ]
    [ , [ @recipients = ] 'recipients [ ; ...n ]' ]
    [ , [ @copy_recipients = ] 'copy_recipients [ ; ...n ]' ]
    [ , [ @blind_copy_recipients = ] 'blind_copy_recipients [ ; ...n ]' ]
    [ , [ @subject = ] 'subject' ]
    [ , [ @body = ] 'body' ]
    [ , [ @body_format = ] 'body_format' ]
    [ , [ @importance = ] 'importance' ]
    [ , [ @sensitivity = ] 'sensitivity' ]
    [ , [ @file_attachments = ] 'attachment [ ; ...n ]' ]
    [ , [ @query = ] 'query' ]
    [ , [ @execute_query_database = ] 'execute_query_database' ]
    [ , [ @attach_query_result_as_file = ] attach_query_result_as_file ]
    [ , [ @query_attachment_filename = ] query_attachment_filename ]
    [ , [ @query_result_header = ] query_result_header ]
    [ , [ @query_result_width = ] query_result_width ]
    [ , [ @query_result_separator = ] 'query_result_separator' ]
    [ , [ @exclude_query_output = ] exclude_query_output ]
    [ , [ @append_query_error = ] append_query_error ]
    [ , [ @query_no_truncate = ] query_no_truncate ]
    [ , [ @mailitem_id = ] mailitem_id ]
    [ , [ @from_address = ] 'from_address' ]
    [ , [ @reply_to = ] 'reply_to' ]
    [ , [ @importance = ] 'importance' ]
    [ , [ @sensitivity = ] 'sensitivity' ]
    [ , [ @body_format = ] 'body_format' ]
    [ , [ @body = ] 'body' ]
    [ , [ @file_attachments = ] 'attachment [ ; ...n ]' ]
    [ , [ @query = ] 'query' ]
    [ , [ @execute_query_database = ] 'execute_query_database' ]
    [ , [ @attach_query_result_as_file = ] attach_query_result_as_file ]
    [ , [ @query_attachment_filename = ] query_attachment_filename ]
    [ , [ @query_result_header = ] query_result_header ]
    [ , [ @query_result_width = ] query_result_width ]
    [ , [ @query_result_separator = ] 'query_result_separator' ]
    [ , [ @exclude_query_output = ] exclude_query_output ]
    [ , [ @append_query_error = ] append_query_error ]
    [ , [ @query_no_truncate = ] query_no_truncate ]
    [ , [ @mailitem_id = ] mailitem_id ]

参数说明:

  • @profile_name:指定用于发送邮件的数据库邮件配置文件的名称。
  • @recipients:指定邮件的收件人,可以是一个或多个邮箱地址,多个地址之间用分号分隔。
  • @copy_recipients:指定邮件的抄送人,格式与@recipients相同。
  • @blind_copy_recipients:指定邮件的密送人,格式与@recipients相同。
  • @subject:指定邮件的主题。
  • @body:指定邮件的正文内容。
  • @body_format:指定邮件正文的格式,可以是'HTML'或'TEXT'。
  • @importance:指定邮件的重要性,可以是'LOW'、'NORMAL'或'HIGH'。
  • @sensitivity:指定邮件的敏感性,可以是'NORMAL'、'PERSONAL'、'PRIVATE'或'CONFIDENTIAL'。
  • @file_attachments:指定邮件的附件,可以是一个或多个文件路径,多个路径之间用分号分隔。
  • @query:指定要执行的查询语句,将查询结果作为邮件正文发送。
  • @execute_query_database:指定执行查询语句的数据库。
  • @attach_query_result_as_file:指定是否将查询结果作为文件附件发送。
  • @query_attachment_filename:指定查询结果作为附件时的文件名。
  • @query_result_header:指定查询结果是否包含列名。
  • @query_result_width:指定查询结果的列宽。
  • @query_result_separator:指定查询结果的列分隔符。
  • @exclude_query_output:指定是否在邮件正文中包含查询结果。
  • @append_query_error:指定是否在邮件正文中包含查询错误信息。
  • @query_no_truncate:指定是否截断查询结果中的长文本。

sp_send_dbmail的应用场景包括但不限于:

  • 发送数据库查询结果给相关人员。
  • 发送系统错误日志给开发人员。
  • 发送定时报表给管理人员。
  • 发送通知邮件给用户。

腾讯云提供了云数据库 TencentDB、云服务器 CVM、云函数 SCF 等产品,可以与sp_send_dbmail结合使用,实现数据库邮件的发送功能。具体产品介绍和使用方法可以参考腾讯云官方文档:

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

领券