ColdFusion cfmail 如何保持格式

Bet*_*ock 3 email coldfusion

在我的 ColdFusion 程序中,我为一个或多个收件人创建电子邮件 (HTML/CSS),并将其放在一个 .cfm 文件中。电子邮件格式很好。当我将保存的文件作为程序运行时,cfmail 标签将电子邮件发送给任何人,这一切正常。但是,在此过程中,我的格式丢失了。我知道当电子邮件到达其目标时,我的本地 CSS 没有理由运行。但如果我能保留我开始的格式就好了。

有没有人对我如何做到这一点有建议。

js1*_*983 5

如果您未type="html"cfmail标签中包含该属性,则可能会影响电子邮件的格式。此外,在cfmail标签中,除了您的内容之外,还嵌入您的风格。例如:

<cfmail from="foo@bar.com" to="foobar@bar.com" subject"test" server="mymailserver" type="html">
  <html>
    <head>
      <style>
        .test { color: ##cc0000; }
      </style>
    </head>
    <body>
      <div class="test">This email is in red</div>
    </body>
  </html>
</cfmail>
Run Code Online (Sandbox Code Playgroud)


Joh*_*ish 5

样式化电子邮件可能很棘手,因为它因客户而异 - 有整篇博客文章专门讨论这一点。例如,头部部分中的样式在某些客户端中被忽略而在其他客户端中被识别。可悲的是,内联样式似乎是“最佳”方法。

在活动监视器网站上有一个很好的概述,如果哪些客户有效:https : //www.campaignmonitor.com/css/

Mailchimp 有一个方便的工具,可以根据您的 HTML/CSS 为您内联样式:http : //templates.mailchimp.com/resources/inline-css/

还值得包含一个纯文本版本以获得最大的兼容性。你可以这样做:

<cfmail to="someone@somewhere.xyz"
        from="me@here.xyz"
        subject="Hello!"
        type="html">
   <cfmailpart type="text/plain" wraptext="60">
     Hello,
     This is plain text version
   </cfmailpart>
   <cfmailpart type="text/html">
     <h3>Hello</h3>
     <p>This is <b style="color:red;">HTML</b> version</p>
   </cfmailpart>
</cfmail>
Run Code Online (Sandbox Code Playgroud)