2013-05-10 55 views
0

我有一個查詢返回多個結果,只有一列中的數據與特定報表編號不同。我想將結果分組爲一個報告編號,並將電子郵件發送給所有行動項目的一個人。下面是我的查詢cfmail組屬性拋出錯誤

<cfquery name="qryCorrectiveDueDate" datasource="#application.config.DSN#"> 
    SELECT FR.report_id, 
      FR.report_number, 
      IR.investigation_id, 
      CA.action_who, 
      CA.action_who_email, 
      CA.action_what, 
      CA.action_when, 
      CA.action_type, 
      CA.action_complete_date 
    FROM xyz_gir.dbo.xyz_flash_report AS FR, 
      xyz_gir.dbo.xyz_investigation_report AS IR, 
      xyz_gir.dbo.xyz_corrective_actions AS CA 
    WHERE FR.report_id = IR.report_id 
    AND IR.investigation_id = CA.investigation_id 
    AND DATEDIFF(day,CA.action_when,GETDATE()) > 1 
    AND CA.action_complete_date IS NULL 
    ORDER BY IR.investigation_id 
</cfquery> 

結果集看起來是這樣的:

report_id report_number investigation_id action_who action_who_email  action_what action_when action_type action_complete_date 
2 13-0002 2 Hans-Joerg Wolf [email protected] Action 1 00:00.0 Repair NULL 
4 13-0004 3 Robert Michael [email protected] fghfgh 00:00.0 Repair NULL 
5 13-0005 4 Masoud Aghel [email protected] sdfsdfsdf 00:00.0 Repair NULL 
5 13-0005 4 Masoud Aghel [email protected] hhjghj 00:00.0 Repair NULL 

我想要做的就是發送一個電子郵件給多行具有相同調查的id action_who_email值。如果我使用CFOUTPUT組認爲這是輸出:

[email protected] 
Report ID: 2 
Report Number: 13-0002 
investigation id: 2 
Action Who :Hans-Joerg Wolf 
Action What: Action 1 
Action When: 2013-04-26 00:00:00.0 
Action type:Repair 
Action Complete Date: 


[email protected] 
Report ID: 4 
Report Number: 13-0004 
investigation id: 3 
Action Who :Robert Michael 
Action What: fghfgh 
Action When: 2013-05-05 00:00:00.0 
Action type:Repair 
Action Complete Date: 


[email protected] 
Report ID: 5 
Report Number: 13-0005 
investigation id: 4 
Action Who :Masoud Aghel 
Action What: sdfsdfsdf 
Action When: 2013-04-29 00:00:00.0 
Action type:Repair 
Action Complete Date: 

Report ID: 5 
Report Number: 13-0005 
investigation id: 4 
Action Who :Masoud Aghel 
Action What: hhjghj 
Action When: 2013-04-29 00:00:00.0 
Action type:Repair 
Action Complete Date: 

,這是我CFOUTPUT:

<cfoutput query="qryCorrectiveDueDate" group="investigation_id"> 

<b>#action_who_email#</b><br> 
    <cfoutput> 
     Report ID: #report_id#</br> 
     Report Number: #report_number#</br> 
     investigation id: #investigation_id#</br> 
      Action Who :#action_who#</br> 
      Action What: #action_what#</br> 
      Action When: #action_when#</br> 
      Action type:#action_type#</br> 
      Action Complete Date: #action_complete_date#</br></br> 
    </cfoutput></br> 

</cfoutput> 

但是,如果我查詢和組CFMAIL做同樣的事情吧,那將引發javax.mail.MessagingException:無法連接到SMTP主機:127.0.0.1,端口:25;錯誤。

我CFMAIL代碼如下

<cfmail query="qryCorrectiveDueDate" from="[email protected]" to="#action_who_email#" group="#investigation_id#" subject="xyz"> 

<p>#action_who#,</p> 
<p>Due Dates for Corrective Actions for the Incident #report_number# have lapsed </p> 
<p>You are receiving this notification, as the Manager/Supervisor to implement the Corrective Actions </p> 
<p>Incident No: #report_number# </p> 
<p>Corrective Action: #action_what#</p> 
<p>Due Date: #action_when#</p> 

</cfmail> 

請注意,我用本地XAMPP運行ColdFusion,雖然郵件不得到發表的,我可以看到他們在ColdFusion中的未交付的文件夾。同一個文件有其他的cfmail標籤,如果這個cfmail標籤被註釋掉,它們不會拋出連接異常。 我很抱歉,如果我的問題是非常通用的,但我要麼與Coldfusion做到這一點,或者我可能不得不寫一個函數來將我的結果集作爲臨時表。我相信,如果我知道如何使這項工作成功,那麼使用coldfusion更容易。

+0

您能否更新您的問題並量化您的意思是「無效」? – 2013-05-10 10:24:32

+0

這個錯誤表明在主機或端口上沒有運行郵件服務器? – 2013-05-10 10:57:24

+0

是的,沒有郵件服務器,但我有其他類似於和來自地址的cfmail標籤,他們只是在coldfusion中去找不到的forlder。我沒有得到這個特定的錯誤。它只是當我在查詢中添加了這個特定的cfmail時,我遇到了這個錯誤。 – amsko 2013-05-10 11:00:05

回答

1

現在你已經刪除了哈希標籤,您的問題可能在電子郵件缺少cfoutput標籤。與cfoutput標記的組屬性類似,您需要使用另一個cfoutput標記遍歷分組記錄。

本地測試CF8。

<cfmail query="q" group="field"> 
    <cfoutput> 
     #field# - #field2# 
    </cfoutput> 
</cfmail> 
+0

這解決了我的問題..謝謝噸! – amsko 2013-05-13 06:06:28

2

我相信你的實際問題是你在組屬性中使用磅符號。

group="#investigation_id#"應該group="investigation_id"

- 編輯 -

這下面的答案是沒有實際意義的OP是誤導。

我想這是因爲你不需要cfoutput標籤裏面的cfmail標籤。雖然它會導致郵件錯誤,這很奇怪。

反正...

我會嘗試在cfmail使用cfsavecontent然後輸出變量。

<cfsavecontent variable = "mailBody"> 
    <cfoutput query="qryCorrectiveDueDate" group="investigation_id"> 
     <b>#action_who_email#</b><br> 
     <cfoutput> 
      Report ID: #report_id#</br> 
      Report Number: #report_number#</br> 
      investigation id: #investigation_id#</br> 
      Action Who :#action_who#</br> 
      Action What: #action_what#</br> 
      Action When: #action_when#</br> 
      Action type:#action_type#</br> 
      Action Complete Date: #action_complete_date#</br></br> 
     </cfoutput> 
     </br> 
    </cfoutput> 
</cfsavecontent> 

<cfmail ...> 
    #mailBody# 
</cfmail> 
+0

嗯,我的cfmail裏面沒有cfoutput標籤。此外,如果我使用savecontent,只是發送一封電子郵件給所有人的所有數據。我想發送一封單獨​​的電子郵件到(根據上述結果集)[email protected]與他同一個報告ID的Action_what值的詳細信息和一個單獨的電子郵件羅伯特等 – amsko 2013-05-10 11:11:56

+0

@amsko *「this是我的輸出......但是如果我用cfmail做同樣的事情......「*讓我相信你在'cfmail'中做了同樣的事情,抱歉誤會。你應該顯示你的'cfmail'代碼實際上是導致錯誤,而不是多餘的東西。 – Travis 2013-05-10 11:16:17

+0

@MichaelGiovanniPumo編輯是不需要的。回滾,它是從OP複製的,並且需要來對輸出進行分組。壞小人。 – Travis 2013-05-10 11:25:42

相關問題