Home >Database >Mysql Tutorial >How to send SQL Server stored procedure emails in format (code example)
The content of this article is about the method of sending SQL Server stored procedure emails in format (code example). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you. .
1. The message received shows:
2. The stored procedure code part:
BEGIN SET NOCOUNT ON; --初始化 Declare @MailTo nvarchar(max) Declare @MailCc nvarchar(max) Declare @MailBcc nvarchar(max) Declare @MailSubject nvarchar(255) Declare @MailBody nvarchar(max) Declare @MailFormat nvarchar(20) DECLARE @SignCount nvarchar(50) --查询表格中异常资料笔数 SELECT @SignCount=COUNT(1) FROM 表名称 WHERE 筛选条件 SET @MailSubject='異常共'+@SignCount+'筆' SET @MailFormat='HTML' SET @MailTo='xxx.zzz@qq.com' --收件人邮件地址 SET @MailCc='xxx.zzz@qq.com' --抄送 SET @MailBcc='xxx.zzz@qq.com' --密送 SET @MailBody='' --发送内容 SET @MailBody = N'Dear Sir/Madam:<br>異常共'+@SignCount+'筆,請及時核對,謝謝!!!<br><H4> 列表如下:</H4>' + --定义邮件表格尺寸大小 N'<table border="1" style="font-size:11px;text-align:center" width="60%">' + --定义列表对应列名称 N'<tr style="font-size:11"><th>工號</th>' + N'<th>姓名</th>' + N'<th>已用天數</th>' + N'<th>實際已用天數</th>' + N'<th>異常狀態</th>' + --表主体结果 CAST ( ( SELECT td = Empid, '', td = EmpCName, '', td = [ULColA29-AdjAnlUsePos-Sum], '', td = VocaTotalHours, '', td = [ULColA29-State], '' FROM 表名称 Form WHERE 筛选条件 FOR XML PATH('tr'), TYPE --将查询出来结果以HTML语言 td/tr显示出来 ) AS NVARCHAR(MAX) ) + N'</table><br>以上為系統發送,請勿回復!!!<br>xx部xx課' declare @i int BEGIN SET @i=0; EXEC asdb.dbo.xx_xxx_xxxxx --执行SQL邮件发送的一个功能地址,这个地址就要去问公司的负责人了 --对应的邮件主体参数带入发送邮件 @profile_name='MIS_SMTP_Mail', --系统设置的邮件发送名称 --公司邮件管理者DB设置 @recipients=@MailTo, @copy_recipients=@MailCc, @blind_copy_recipients=@MailBcc, @subject=@MailSubject, @body=@MailBody, @body_format=@MailFormat SET @i=1; END END
The above is the detailed content of How to send SQL Server stored procedure emails in format (code example). For more information, please follow other related articles on the PHP Chinese website!