需要使用coldfusion 10的smtp设置

Need to use the smtp settings of coldfusion 10

coldfusion 10 中有 Application.cfc 的新设置,即:

   this.smtpServersettings = as a structure

我可以在这里对值进行硬编码,但是我将我的邮件设置保存在数据库中,我想在这里使用这些值,是否可以在这里使用数据库设置。

这是我的更新:

<cfcomponent hint="File for the Website" output="false">
    <cfsetting showdebugoutput="no">
    <cfset this.name = "myProject1">
    <cfset this.applicationTimeout = createTimeSpan(2,0,0,0)>
    <cfset this.clientmanagement= "yes">
    <cfset this.loginstorage = "session">
    <cfset this.sessionmanagement = "yes">
    <cfset this.sessiontimeout = CreateTimeSpan(0,0,40,0) />
    <cfset this.setClientCookies = "yes">
    <cfset this.scriptProtect = "all">
    <cfset this.setDomainCookies = true>
    <cfset this.customTagPaths = ExpandPath('customtags')>
    <cfset this.datasource = {name="myDB"}>
    <cfset this.smtpServersettings = {structur as username,password and mail settings}>

但是这个值需要通过数据库,你能给我举个例子吗

是的,您应该能够通过数据库查询设置 this.smtpServersettings 变量的值。对于它的价值,我认为该设置自 ColdFusion 9 以来就可用。

您只需执行以下操作即可。

  1. 运行 您从数据库中获取值的查询
  2. 创建新结构
  3. 将三个变量分配给该结构;服务器、用户名和密码
  4. this.smtpServersettings 变量分配给您的新结构

当然你需要添加一些代码来做一些事情if/when你的数据库查询失败了。

问题更新后更新

只需执行如下操作(伪代码):

<cfcomponent hint="File for the Website" output="false">
    <cfsetting showdebugoutput="no">
    <cfset this.name = "myProject1">
    <cfset this.applicationTimeout = createTimeSpan(2,0,0,0)>
    <cfset this.clientmanagement= "yes">
    <cfset this.loginstorage = "session">
    <cfset this.sessionmanagement = "yes">
    <cfset this.sessiontimeout = CreateTimeSpan(0,0,40,0) />
    <cfset this.setClientCookies = "yes">
    <cfset this.scriptProtect = "all">
    <cfset this.setDomainCookies = true>
    <cfset this.customTagPaths = ExpandPath('customtags')>
    <cfset this.datasource = {name="myDB"}>

    <!--- run your query here --->
    <!--- check your query and do something appropriate if/when it fails --->
    <cfset this.MyStructure = StructNew()>
    <cfset this.MyStructure.server = this.MyQuery.ServerNameVariable>
    <cfset this.MyStructure.username = this.MyQuery.UserNameVariable>
    <cfset this.MyStructure.password = this.MyQuery.PasswordVariable>

    <cfset this.smtpServersettings = this.MyStructure>

您还需要注意,这样做会 运行 在 每个 页面请求上进行查询。确保它 运行 很快。