SQL 中调用Cdo.Message 发Email 乱码问题

talantlee 2010-12-17 04:25:55
SQL 服务器为英文的

现在Email 内容需包含繁体



-- exec Sp_SendMail @from,@pwd,@to,@cc,@bcc,@title,@body,@errMsg
CREATE procedure Sp_SendMail
@from varchar(100),
@pwd varchar(20),
@to varchar(100),
@cc varchar(300),
@bcc varchar(100),
@title nvarchar(100),
@body nvarchar(4000),
@errMsg varchar(200) out
as


Declare @hr int
declare @errnum as int
declare @object as int
set @errnum=0 --正确的
if isnull(@from,'')=''
begin
select @from = 'emailaddress@xxx.com.cn'
select @pwd = '1234'
end

set @bcc=''
EXEC @hr = sp_OACreate 'cdo.Message', @object OUT

EXEC @hr = sp_OASetProperty @object, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendusing").Value','2'
EXEC @hr = sp_OASetProperty @object, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpserver").Value', '192.168.150.251'

EXEC @hr = sp_OASetProperty @object, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/usemessageresponsetext").Value','1'

EXEC @hr = sp_OASetProperty @object, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate").Value','1'
EXEC @hr = sp_OASetProperty @object, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendusername").Value', @from
EXEC @hr = sp_OASetProperty @object, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendpassword").Value',@pwd
--EXEC @hr = sp_OASetProperty @object, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/languagecode").Value','0x0804'




EXEC @hr = sp_OAMethod @object, 'Configuration.Fields.Update', null
EXEC @hr = sp_OASetProperty @object, 'To', @to
--EXEC @hr = sp_OASetProperty @object, 'BodyPart.Charset','big5'
EXEC @hr = sp_OASetProperty @object, 'Bcc', @bcc
EXEC @hr = sp_OASetProperty @object, 'Cc', @cc
EXEC @hr = sp_OASetProperty @object, 'From', @from
EXEC @hr = sp_OASetProperty @object, 'Subject', @title
EXEC @hr = sp_OASetProperty @object, 'BodyFormat', 'MailFormat.Html'
--EXEC @hr = sp_OASetProperty @object, 'BodyEncoding', 'UTF8'

EXEC @hr = sp_OASetProperty @object, 'HTMLBodyPart.Charset', 'Big5'
EXEC @hr = sp_OASetProperty @object, 'HtmlBody',@body





-- add attachment
--EXEC @hr = sp_OAMethod @object, 'AddAttachment', NULL

EXEC @hr = sp_OAMethod @object, 'Send', NULL

IF @hr <> 0
BEGIN
EXEC sp_OAGetErrorInfo @object
set @errnum=@hr
set @errMsg= @object
END
--PRINT 'success'
EXEC @hr = sp_OADestroy @object
set @errMsg=isnull(@errMsg,'')
GO

exec Sp_SendMail '','','dagger.li@nienmade.com.cn','','',N'中那個國',N'中那個國',''
...全文
246 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
talantlee 2010-12-20
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 billpu 的回复:]
恭喜恭喜 cdo到现在还没淘汰吗
[/Quote]
据我所知,本公司服务器环境6年没变......
dawugui 2010-12-18
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 talantlee 的回复:]
EXEC @hr = sp_OASetProperty @object, 'BodyPart.Charset', 'utf-8'
晕就可以了
[/Quote]恭喜,我接分.
billpu 2010-12-17
  • 打赏
  • 举报
回复
恭喜恭喜 cdo到现在还没淘汰吗
talantlee 2010-12-17
  • 打赏
  • 举报
回复

EXEC @hr = sp_OASetProperty @object, 'BodyPart.Charset', 'utf-8'
晕就可以了

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧