Coldfusion-用于保存空白文件的电子邮件的图表

时间:2018-07-27 19:47:13

标签: coldfusion coldfusion-11 coldfusion-2016 cfmail cfchart

SO。我处于死胡同,希望有人可以帮助您解决这个问题。并先谢谢您。

在ColdFusion 2016服务器上处理自动电子邮件。 (我也在CF11上进行了测试,并且有同样的问题,顺便说一句。)

该电子邮件旨在包含一些信息和10个小型迷你图类型图表。 到目前为止,该电子邮件正在按设计工作。对于当前收件人,它将生成正确的十张图表并发送电子邮件。

每个图表都使用生成的uuid文件名保存。 但是,每个图表文件都保存为1kb,并在电子邮件中显示为错误类型图像。

示例: error image

我知道图表可以正确生成,因为当我将“格式”从“ png”更改为“ html”时,会得到以下输出:

enter image description here

我还有其他几封电子邮件,它们在其中生成图表图像,保存到磁盘,然后附加到电子邮件。唯一的区别是,由于图表太多,因此我试图动态设置图表“名称”,并引用名称数组。

我也有数组来存储cid的文件路径和内容信息。

代码:

<!--- create charts --->
<cfset chartnames = [
  "risk1"
  ,"risk2"
  ,"risk3"
  ,"risk4"
  ,"risk5"
  ,"risk6"
  ,"risk7"
  ,"risk8"
  ,"risk9"
  ,"risk10"
]/>
<cfset chartfiles = [
  "chartfile1"
  ,"chartfile2"
  ,"chartfile3"
  ,"chartfile4"
  ,"chartfile5"
  ,"chartfile6"
  ,"chartfile7"
  ,"chartfile8"
  ,"chartfile9"
  ,"chartfile10"
]/>
<cfset mktcontent = [
  "mktcontent1"
  ,"mktcontent2"
  ,"mktcontent3"
  ,"mktcontent4"
  ,"mktcontent5"
  ,"mktcontent6"
  ,"mktcontent7"
  ,"mktcontent9"
  ,"mktcontent10"
]/>

<cfset metrics = [
  "ACCESSORY_DISCOUNT_SCORE"
  ,"DEVICE_DISCOUNT_SCORE"
  ,"WAIVED_FEES_SCORE"
  ,"OCC_SCORE"
  ,"NATIONAL_RANK"
  ,"RETURN_RATE_SCORE"
  ,"INV_SHR_PCT_SCORE"
  ,"INC_SHR_COST_SCORE"
  ,"INV_SHR_UNITS_SCORE"
  ,"TOTAL_SCORE"
]/>

<cfset titles = [
  "Accessory Discount"
  ,"Device Discount"
  ,"Waived Fees"
  ,"OCCs"
  ,"National Rank"
  ,"Return Rate"
  ,"Shrink %"
  ,"Shrink Cost"
  ,"Shrink Units"
  ,"Total Score"
]/>


<!----- this will generate a small sparkline chart for each of the ten metrics  ------>

<!----- grabbing column names, cleaning up the list to remove RPT_DT  ------>
<cfset tempArray=listToArray(#columns.columnList#)>
<cfscript> 
  ArrayDelete(#tempArray#,"RPT_DT"); 
</cfscript>
<cfdump var = #tempArray# />

<cfset column_list = ArrayToList(#tempArray#) />

<!----- loop through column names and generate charts ------>
<cfloop list=#column_list# index = "col">

  <cfset position=ArrayFind(#metrics#,#col#)>
  <cfset title = #titles[position]# />
  <cfdump var=#title# />
  <!----- tiny queries to set custom scale from/to for each chart------>

  <cfquery dbtype="query" name="scalefrom"> select MIN(#col#) from TERRITORY_DAILY_AVG </cfquery>
  <cfdump var=#col# />
  <cfquery dbtype="query" name = "scaleto"> select MAX(#col#) from TERRITORY_DAILY_AVG  </cfquery>
  <cfset scalefrom = #scalefrom.column_0[1]# - 2 />
  <cfset scaleto = #scaleto.column_0[1]# + 2 />

  <cfdump var=#scalefrom# />
  <cfdump var=#scaleto# />

  <cfchart 
    format="png" 
    showMarkers = "no"
    XAxisType="none"
    scaleFrom = #scalefrom#
    scaleTo = #scaleto# 
    showLegend="no"
    name=#chartnames[position]# 
    chartwidth="200" 
    chartheight="150" 
  >
    <cfchartseries  type="line" seriesColor="##168ADB" query="TERRITORY_DAILY_AVG" itemcolumn="RPT_DT" valuecolumn=#metrics[position]#>
    </cfchartseries>
  </cfchart>

  <!--- create a unique name and write the chart to disk--->
  <cfset myid = createuuid()>

  <cfset chartfiles[position] = "#expandPath("./attachments/#myid#.jpg")#">
  <cfset chartfile=chartfiles[position] />
  <cfset mktcontent[position] = lcase("#myid##cgi.server_name#")>
  <cffile action="write" file=#chartfile# output=#chartnames[position]#>

</cfloop>   

文件名和内容ID数组正在更新,据我所知,它们具有正确的信息:

enter image description here

然后为每个图表设置cfmailparam。

            <cfloop from="1" to="10" index="q">
            <!--- attach the images to the email --->
            <!---the charts--->
            <cfset content=#mktcontent[q]# />
            <cfset chrtfile=#chartfiles[q]# />
            <cfmailparam file=#chrtfile# disposition="inline" contentid=#content#>
            </cfloop>

然后,在电子邮件正文中,尝试将其吐出:

            <cfloop from="1" to="10" index="qq">
            <!---sparkline charts--->
            <cfset chart_to_display=#mktcontent[qq]#/>
            chart to display:
            <cfdump var="#chart_to_display#" />
            <table>
                <tr>    
                    <td width="auto" align="center">
                        <img src="cid:#chart_to_display#">
                    </td>
                </tr>
            </table>
            </cfloop>

从本质上讲,这是我处理所有电子邮件图表的过程。 “格式”为“ png”,文件另存为.jpg,设置内容ID内容,将其附加到电子邮件,然后在电子邮件中显示。这次没有那么多。

这是#chart_to_display#cfdumped的最终输出:

enter image description here

再次感谢,祝您周末愉快。

0 个答案:

没有答案