我有一个查询,它返回多个结果,其中只有一列中的数据,对于特定的报告号不同。我想将结果分组为一个报告编号,并将所有操作项发送电子邮件给一个人。下面是我的查询
<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 hans-joerg.wolf@xyz.com Action 1 00:00.0 Repair NULL
4 13-0004 3 Robert Michael robert.michael@xyz.com fghfgh 00:00.0 Repair NULL
5 13-0005 4 Masoud Aghel Masoud.Aghel@xyz.com sdfsdfsdf 00:00.0 Repair NULL
5 13-0005 4 Masoud Aghel Masoud.Aghel@xyz.com hhjghj 00:00.0 Repair NULL
我想做的是发送一封电子邮件到action_who_email值多行具有相同的调查id。如果我使用cfoutput group属性,这是输出:
hans-joerg.wolf@xyz.com
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:
robert.michael@xyz.com
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:
Masoud.Aghel@xyz.com
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:
And This is my 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="EHS@jdsu.com" 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>
请注意,我在本地运行Coldfusion与xampp,虽然邮件没有得到交付,我可以看到他们在Coldfusion的未交付文件夹。同一个文件有其他cfmail标记,如果这个cfmail标记被注释掉,这些标记不会抛出连接异常。我很抱歉,如果我的问题是非常通用的,但我要么要用coldfusion这样做,要么我可能要写一个函数来处理我的结果集作为一个临时表。如果我知道怎么做的话,我相信用冷融合会更容易。
我认为你的实际问题是你在组属性中使用了磅号。
group="#investigation_id#"
应为group="investigation_id"
——编辑——
下面的答案是没有意义的,因为OP是误导性的。
我认为这是因为你不需要cfoutput
标签内的cfmail
标签。但奇怪的是,它会导致邮件错误。
无论如何……
我会尝试使用cfsavecontent
,然后在cfmail
中输出变量。
<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>
现在您已经删除了散列标签,您的问题可能是电子邮件中缺少cfoutput
标签。与cfoutput
标记的group属性类似,您需要另一个cfoutput
标记来遍历分组的记录。
在CF8本地测试。
<cfmail query="q" group="field">
<cfoutput>
#field# - #field2#
</cfoutput>
</cfmail>