快速业务通道

SQL 2005 发送邮件 存储过程

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-02-06
0),
@CUST_NAME varchar(50),
@vcount int
begin
set @vcount=1
set @str=''''
Declare c_at Cursor
FOR   

select distinct area,country,cust_no,cust_name from [dbo].[TYAN_SERVICE_SITE] where  area is not null and cust_name is not null and ship_location is not null and country is not null and cust_no is not null and (CUST_TYPE is null or SERVICE_SITE is null )

OPEN c_at
FETCH NEXT FROM c_at INTO @AREA,@COUNTRY,@CUST_NO,@CUST_NAME
  WHILE (@@FETCH_STATUS = 0)
  BEGIN
set @str=@str+''<tr align=center>''
set @str=@str+''<td >''+@AREA+''</td>''
set @str=@str+''<td >''+@COUNTRY+''</td>''
set @str=@str+''<td >''+@CUST_NO+''</td>''
set @str=@str+''<td >''+@CUST_NAME+''</td>''
set @vcount=@vcount+1
FETCH NEXT FROM c_at INTO @AREA,@COUNTRY,@CUST_NO,@CUST_NAME
  END

-------这里为你要显示的数据  end---------------------
CLOSE c_at
DEALLOCATE c_at
end
Set @mailbody = @mailbody+@str+''</table></body></html>''
Exec @hr = sp_OACreate ''jmail.message'', @object OUTPUT
Exec @hr = sp_OASetProperty @object, ''Charset'', ''BIG5''

--@recipient--你的收件人邮箱地址---------------------------------------------------
Exec @hr = sp_OAMethod @object, ''AddRecipient'',NULL,''your mailaddress''

--Exec @hr = sp_OAMethod @object, ''AddRecipientBCC'',NULL,''your mailaddress''

Exec @hr = sp_OASetProperty @object, ''Subject'',@subject
Exec @hr = sp_OAsetProperty @object, ''HTMLBody'' ,@mailbody
Exec @hr = sp_OAsetProperty @object, ''Priority'' , 1

If Not @sender is null
Exec @hr = sp_OASetProperty @object, ''From'', @sender

If Not @sendername is null
Exec @hr = sp_OASetProperty @object, ''FromName'', @sendername

--自动邮件 begin
Exec @hr = sp_OAMethod @object, ''Send'', null,@serveraddress
Exec @hr = sp_OAGetErrorInfo @object, @source OUTPUT, @description OUTPUT

if (@hr = 0)
Begin
Set @output=''錯誤源: ''+@source
Print @output
Select @output = ''錯

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号