以下列舉使用sqlserver 傳送郵件的3個示例:
此示例使用電子郵件位址 [email protected] 向 dan wilson 傳送電子郵件。該郵件的主題為 automated success message。郵件正文包含一句話 'the stored procedure finished successfully'。
exec msdb.dbo.sp_send_dbmail@profile_name = 'adventureworks administrator',
@recipients = '[email protected]',
@body = 'the stored procedure finished successfully.',
@subject = 'automated success message' ;
此示例使用電子郵件位址 [email protected] 向 dan wilson 傳送電子郵件。該郵件的主題為 work order count。資料庫郵件將該結果附加為文字檔案。
exec msdb.dbo.sp_send_dbmail@profile_name = 'adventureworks administrator',
@recipients = '[email protected]',
@query = 'select count(*) from adventureworks.production.workorder
where duedate > ''2004-04-30''
and datediff(dd, ''2004-04-30'', duedate) < 2' ,
@subject = 'work order count',
@attach_query_result_as_file = 1 ;
此示例使用電子郵件位址 [email protected] 向 dan wilson 傳送電子郵件。郵件的主題為 work order list,幷包含乙個 html 文件,資料庫郵件使用 html 格式傳送該郵件。
declare @tablehtml nvarchar(max) ;
set @tablehtml =
n'' +
n'' +
n'work order id
product id' +
n'name
order qty
due date' +
n'expected revenue
' +cast ( ( select td = wo.workorderid, '',
td = p.productid, '',
td = p.name, '',
td = wo.orderqty, '',
td = wo.duedate, '',
td = (p.listprice - p.standardcost) * wo.orderqty
from adventureworks.production.workorder as wo
join adventureworks.production.product as p
on wo.productid = p.productid
where duedate > '2004-04-30'
and datediff(dd, '2004-04-30', duedate) < 2
order by duedate asc,
(p.listprice - p.standardcost) * wo.orderqty desc
for xml path('tr'), type) as nvarchar(max) ) +n'' ;
exec msdb.dbo.sp_send_dbmail @recipients='[email protected]',
@subject = 'work order list',
@body = @tablehtml,
@body_format = 'html' ;
以上示例均測試可行。
SQL Server中傳送郵件的新方式
說是新方式,其實也是早就用到的技術了,所以放上來!在.net中,大家知道,可以使用system.web.mail來傳送郵件。在framework 1.1下支援驗證。private void page load object sender,system.eventargs e 以前我曾寫過在.net下...
C 中傳送郵件
using system using system.collections.generic using system.componentmodel using system.data using system.drawing using system.linq using system.text u...
springMVC中傳送郵件可傳送附件
以html傳送 bodypart bodypart new mimebodypart bodypart.setcontent content,text html charset utf 8 multipart multipart new mimemultipart multipart.addbody...