您可以使用 SQL Server 中的电子邮件功能来发送电子邮件。
配置 SQL Server 后(点击此链接);您可以简单地循环浏览每封电子邮件,如下所示:
USE msdb
GO
EXEC sp_send_dbmail @profile_name='PinalProfile',
@recipients='tomcruise@Example.com',
@subject='Your Order',
@body='Hi there.'
更新
这是一个如何遍历记录的示例:
declare @temp as table
(
Id int identity,
OrderId int,
First varchar(255),
Last varchar(255),
Email varchar(512)
)
insert into @temp
Select OrderId, First , Last ,Email from Orders where Approval is Null
declare @email varchar(512)
, @index int=1
, @upper_bound int
, @subject varchar(500)
select @upper_bound=max(Id) from @temp
while(@index<=@upper_bound)
BEGIN
select @email=email,@subject='Your order number '+OrderID from @temp where Id=@index
EXEC msdb.dbo.sp_send_dbmail @profile_name='profile',
@recipients=N@email,
@subject=@subject,
@body='Whatever you want to say here.'
select @index=@index+1
END
-- You are done