2010-05-05 29 views
0

J'ai un morceau de code cdosys qui s'exécute correctement et génère des messages électroniques avec mon serveur SQL Server 2008 en parlant à un serveur MS Exchange 2003. Cependant, le nom de provenance n'apparaît pas sur les e-mails quand ils arrivent. Y a-t-il un défaut dans le code, n'est-ce pas possible de cette façon?Impossible d'ajouter FromName à e-mail en utilisant cdosys dans SQL Server 2008

Merci à l'avance

usp_send_cdosysmail 
@from varchar(500), 
@to text, 
@bcc text , 
@subject varchar(1000), 
@body text , 
@smtpserver varchar(25), 
@bodytype varchar(10) 
as 
declare @imsg int 
declare @hr int 
declare @source varchar(255) 
declare @description varchar(500) 
declare @output varchar(8000) 
exec @hr = sp_oacreate 'cdo.message', @imsg out 
exec @hr = sp_oasetproperty @imsg, 
'configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendusing").value','2' 

exec @hr = sp_oasetproperty @imsg, 
    'configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpserver").value', 
    @smtpserver 

exec @hr = sp_oamethod @imsg, 'configuration.fields.update', null 
exec @hr = sp_oasetproperty @imsg, 'to', @to 
exec @hr = sp_oasetproperty @imsg, 'bcc', @bcc 
exec @hr = sp_oasetproperty @imsg, 'from', @from 
exec @hr = sp_oasetproperty @imsg, 'fromname','A From Name' 
exec @hr = sp_oasetproperty @imsg, 'subject', @subject 

-- if you are using html e-mail, use 'htmlbody' instead of 'textbody'. 

exec @hr = sp_oasetproperty @imsg, @bodytype, @body 
exec @hr = sp_oamethod @imsg, 'send', null 

-- sample error handling. 
if @hr <>0 
select @hr 
begin 
exec @hr = sp_oageterrorinfo null, @source out, @description out 
if @hr = 0 
begin 
select @output = ' source: ' + @source 
print @output 
select @output = ' description: ' + @description 
print @output 
end 
else 
begin 
print ' sp_oageterrorinfo failed.' 
return 
end 
end 
exec @hr = sp_oadestroy @imsg 

Répondre

1

Vous devriez également pouvoir

sp_oasetproperty @imsg, 'from', '"Mr Bob T. Fantastic" <[email protected]>'

+0

génie frickin, merci et bon nom –