2010-09-20 32 views
0

我創建了一個發送自動電子郵件的過程。電子郵件到達的地址,一切似乎工作正常,但身體無法看到。我正在使用sql 2005和MS exchange server 2007.編寫正文的過程部分如下。在sql server 2005中使用sp_send_dbmail時無法看到電子郵件的正文

declare @bodymsg as varchar(1000) 
set @bodymsg = 'The application ' 
set @bodymsg = @bodymsg + @appnum 
set @bodymsg = @bodymsg + ' have been auto assign to you by the call center auto assign program.' 
set @bodymsg = @bodymsg + CHAR(13) 
set @bodymsg = @bodymsg + 'The borrower information is as follow:' 
set @bodymsg = @bodymsg + CHAR(13) 
set @bodymsg = @bodymsg + 'Name: ' 
set @bodymsg = @bodymsg + @borrower 
set @bodymsg = @bodymsg + CHAR(13) 
set @bodymsg = @bodymsg + 'Email: ' 
set @bodymsg = @bodymsg + @borremail 
set @bodymsg = @bodymsg + CHAR(13) 
set @bodymsg = @bodymsg + 'Phone: ' 
set @bodymsg = @bodymsg + @borrhome 
set @bodymsg = @bodymsg + CHAR(13) 
set @bodymsg = @bodymsg + 'Cellphone: ' 
set @bodymsg = @bodymsg + @borrcell 
set @bodymsg = @bodymsg + CHAR(13) 
set @bodymsg = @bodymsg + CHAR(13) 
set @bodymsg = @bodymsg + 'Please contact the borrower ASAP.' 

execute [msdb].[dbo].[sp_send_dbmail] 
    @profile_name = 'CallCenter',   
    @recipients = @email, 
    @subject  = @subjectmsg, 
    @body   = @bodymsg, 
    @body_format = 'TEXT' 

回答

0

只要你執行之前sp_send_dbmail打印@bodymsg參數,以便您瞭解數據已正確建立。

例如

PRINT @bodymsg 
execute [msdb].[dbo].[sp_send_dbmail] 
@profile_name = 'CallCenter',   
@recipients = @email, 
@subject  = @subjectmsg, 
@body   = @bodymsg, 
@body_format = 'TEXT' 

當你傳遞一些參數,它其中的一個可以設置@bodymsg爲NULL

+0

謝謝你是這個問題。 – 2010-09-20 18:10:17

1

只需添加到kevchadders回覆,當你調用PRINT @bodymsg,如果它在打印什麼那麼你知道這是一個空串聯問題。

如果您將每個變量包含在ISNULL()函數中,那麼將更容易找到哪個變量導致問題。

例如。

set @bodymsg = @bodymsg + ISNULL(@appnum,'') 

然後電子郵件的正文將被打印,但會有一個缺少參數。然後你需要找出爲什麼參數丟失。

+0

+1好點... – kevchadders 2010-09-21 07:33:45

0

通常,當我遇到sp_send_dbmail的這個問題時,它與傳遞更多字符或數據有關,然後@body變量可以處理。 SQL Server拋出一個錯誤,指出數據將被截斷。錯誤不是致命的,所以存儲過程繼續運行,導致沒有正文的電子郵件。

相關問題