首页 \ 问答 \ 如何创建电子邮件回复/方法来编码回复?(How to create email reply / method to code a reply?)

如何创建电子邮件回复/方法来编码回复?(How to create email reply / method to code a reply?)

我正在构建一个代表我的应用用户响应电子邮件的应用。 这些电子邮件会发送给我的用户,并被我的应用拦截以自动回复他们的客户。 电子邮件来自第三方并包含品牌格式。

我的PHP应用程序接收电子邮件的完整HTML,将其存储在MySQL表中,然后创建回复并将HTML附加到电子邮件底部的<hr/>下。

这有效,它看起来像一个回复(这是我的意图(尽管我会建立一些头部细节,使其看起来更合理,就好像它已在Outlook或类似回复))。

然而,我的问题是,这种方法会伤害回复格式 - 它似乎采用了回复底部的原始电子邮件HTML格式的线条高度。

因此我的问题是,如何创建回复电子邮件? 做我正在做的事情,更好地设计我的回复,或者我需要做更多的完整原创,而不仅仅是HTML输出。 在电子邮件中使用HTML标签甚至可以吗?

如果答案是这样的,我会喜欢它:从电子邮件中提取X并用开源Y库构建回复:)

编辑:电子邮件的例子按要求

该第三方电子邮件包含一个如下所示的头像:

<html>
<head>
<style type='text/css'>
body{font-family: arial,helvetica,sans-serif;}
a{color: #06c;}
p{margin:0;}
#message{width:600px;margin:0 auto;}
.legal{margin-top:2em;}
.footer{margin-top:1em;padding:5px;background:#999999;color:#fff;}
.footer a{color:#fff;}
.senderName,.label{font-weight:bold;}
.link,.label,.hint{margin-top: 20px;}
.header-separator{height:4px;background-color:#e4002b;width:100%;margin-top:17px;}
tr,td{vertical-align:top;text-align:left;}
img{border:0;}
${css!""}
</style>
</head>
<body>
<div id='message'>
...

而我的用户电子邮件模板(内置于TinyMCE中)将如下所示:

<p><span style="font-family: Calibri, sans-serif; font-size: 11pt; line-height: 14pt;">Dear [name],</span></p>
<p><span style="font-family: Calibri, sans-serif; font-size: 11pt; line-height: 14pt;">Thanks for your enquiry
...

当我将电子邮件发送到电子邮件服务时,这很简单:

$emailreply = $userTemplate . '<hr/>' . $originalEnquiry;

当然,这不够好? 另外,这是我提到的电子邮件,其中行高正在受到影响 - 所以我的用户模板没有按照设计发送。


I'm building an app which responds to emails on behalf of my app users. These emails are sent to my users and intercepted by my app to auto-respond to their clients. The emails come from third parties and contain branded formatting.

My PHP app takes the full HTML of the email, stores it in a MySQL table then creates a reply and appends the HTML under a <hr/> at the bottom of the email.

This works and it looks like a reply (which is my intention (although I will build some header detail to make it look more legitimate as if it was replied to in Outlook or similar)).

My problem, however, is that this method hurts the reply formatting - it seems to take on styles like line-height from the original email HTML at the bottom of the reply.

Thus my question is, how do I create a reply email? Do do what I'm doing and style my reply better, or do I need to do more with the complete original, not just the HTML output. And is it even ok to have to HTML tags in an email?

I would love it if the answer was something like: extract the X from the email and build a reply with the opensource Y library :)

EDIT: Email examples as requested

This third party email contains a head that looks like this:

<html>
<head>
<style type='text/css'>
body{font-family: arial,helvetica,sans-serif;}
a{color: #06c;}
p{margin:0;}
#message{width:600px;margin:0 auto;}
.legal{margin-top:2em;}
.footer{margin-top:1em;padding:5px;background:#999999;color:#fff;}
.footer a{color:#fff;}
.senderName,.label{font-weight:bold;}
.link,.label,.hint{margin-top: 20px;}
.header-separator{height:4px;background-color:#e4002b;width:100%;margin-top:17px;}
tr,td{vertical-align:top;text-align:left;}
img{border:0;}
${css!""}
</style>
</head>
<body>
<div id='message'>
...

And my user email templates (built in TinyMCE) will look something like this:

<p><span style="font-family: Calibri, sans-serif; font-size: 11pt; line-height: 14pt;">Dear [name],</span></p>
<p><span style="font-family: Calibri, sans-serif; font-size: 11pt; line-height: 14pt;">Thanks for your enquiry
...

When I send the email to the email service it's as simple:

$emailreply = $userTemplate . '<hr/>' . $originalEnquiry;

Surely, that's not good enough? Also, this is the email that I mentioned where line-height is being affected - so my user templates are not sending as designed.


原文:https://stackoverflow.com/questions/41712741
更新时间:2023-02-07 07:02

最满意答案

更整洁优雅的解决方案:

注意:文件扩展名.gzip似乎很奇怪,一般来说,我们将一个gziped文件命名为.gz ,因此在本例中,如果您坚持使用.gzip ,则使用.gz而不是.gzip ,只需替换以下所有扩展名配置文件。


首先编码,这就是web.config所需的全部内容

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <staticContent>
      <remove fileExtension=".js.gz" />
      <remove fileExtension=".css.gz" />
      <remove fileExtension=".png.gz" />
      <remove fileExtension=".jpg.gz" />
      <remove fileExtension=".gif.gz" />
      <remove fileExtension=".svg.gz" />
      <remove fileExtension=".html.gz" />
      <remove fileExtension=".json.gz" />
      <mimeMap fileExtension=".js.gz" mimeType="application/javascript" />
      <mimeMap fileExtension=".css.gz" mimeType="text/css" />
      <mimeMap fileExtension=".png.gz" mimeType="image/png" />
      <mimeMap fileExtension=".jpg.gz" mimeType="image/jpeg" />
      <mimeMap fileExtension=".gif.gz" mimeType="image/gif" />
      <mimeMap fileExtension=".svg.gz" mimeType="image/svg+xml" />
      <mimeMap fileExtension=".html.gz" mimeType="text/html" />
      <mimeMap fileExtension=".json.gz" mimeType="application/json" />
    </staticContent>

    <rewrite>
      <outboundRules rewriteBeforeCache="true">
        <rule name="Custom gzip file header">
          <match serverVariable="RESPONSE_CONTENT_ENCODING" pattern=".*" />
          <conditions>
            <add input="{REQUEST_URI}" pattern="\.gz$" />
          </conditions>
          <action type="Rewrite" value="gzip"/>
        </rule>
      </outboundRules>

      <rules>
        <rule name="Rewrite gzip file">
          <match url="(.*)"/>
          <conditions>
            <add input="{HTTP_ACCEPT_ENCODING}" pattern="gzip" />
            <add input="{REQUEST_FILENAME}.gz" matchType="IsFile" />
          </conditions>
          <action type="Rewrite" url="{R:1}.gz" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

而且,它是如何工作的:

为了实现成功的gziped数据传输,我们需要:

  • 客户端接受gziped数据, Accept-Encoding
  • 带有Content-Encoding的标题响应
  • 正确的MIME类型,原始文件是,但不是application/gzip
  • Gziped文件

这四个条件必须同时满足。

如果使用Content-Encoding: gzip发送一个未压缩的文件,浏览器将返回一个错误;

如果您发送没有Content-Encoding标头或不匹配的MIME类型的压缩文件,页面可能会返回一些Zenith Star的文本。

所以我们正在做的是:

  • 重新定义每种类型的gziped文件的MIME
  • 如果客户端接受gziped文件,则直接将响应文件重定向到服务器端的gziped版本(而不是302/303/307响应)
  • 只有当客户端发送头部Accept-Encoding重写Content-Encoding响应头的头部

这个解决方案适用于我的IIS7,不知道它是否也适用于IIS10。

如果遇到任何问题,请告诉我:D


A more neat and elegant solution:

NOTICE: The file extension .gzip seems strange, in general, we name a gziped file as .gz, so in this example, we use .gz instead .gzip, if you insist on .gzip, just replace all the extensions in the following config file.


Code first, this is what all we need for web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <staticContent>
      <remove fileExtension=".js.gz" />
      <remove fileExtension=".css.gz" />
      <remove fileExtension=".png.gz" />
      <remove fileExtension=".jpg.gz" />
      <remove fileExtension=".gif.gz" />
      <remove fileExtension=".svg.gz" />
      <remove fileExtension=".html.gz" />
      <remove fileExtension=".json.gz" />
      <mimeMap fileExtension=".js.gz" mimeType="application/javascript" />
      <mimeMap fileExtension=".css.gz" mimeType="text/css" />
      <mimeMap fileExtension=".png.gz" mimeType="image/png" />
      <mimeMap fileExtension=".jpg.gz" mimeType="image/jpeg" />
      <mimeMap fileExtension=".gif.gz" mimeType="image/gif" />
      <mimeMap fileExtension=".svg.gz" mimeType="image/svg+xml" />
      <mimeMap fileExtension=".html.gz" mimeType="text/html" />
      <mimeMap fileExtension=".json.gz" mimeType="application/json" />
    </staticContent>

    <rewrite>
      <outboundRules rewriteBeforeCache="true">
        <rule name="Custom gzip file header">
          <match serverVariable="RESPONSE_CONTENT_ENCODING" pattern=".*" />
          <conditions>
            <add input="{REQUEST_URI}" pattern="\.gz$" />
          </conditions>
          <action type="Rewrite" value="gzip"/>
        </rule>
      </outboundRules>

      <rules>
        <rule name="Rewrite gzip file">
          <match url="(.*)"/>
          <conditions>
            <add input="{HTTP_ACCEPT_ENCODING}" pattern="gzip" />
            <add input="{REQUEST_FILENAME}.gz" matchType="IsFile" />
          </conditions>
          <action type="Rewrite" url="{R:1}.gz" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

And, here are how it works:

In order to achieve a successful gziped data transmission, we need:

  • Client side accept gziped data, Accept-Encoding
  • Response with a header with Content-Encoding
  • Proper MIME type, as the original file is, BUT NOT application/gzip
  • Gziped file

The four conditions must be satisfied at the same time.

If you send an uncompressed file with Content-Encoding: gzip, the browser will return an error;

If you send a compressed file without a Content-Encoding header, or a mismatched MIME type, the page may return some Zenith Star's text.

So what we are doing is:

  • Redefine each type of gziped file's MIME
  • If the client side accept a gziped file, then redirect the response file to a gziped version on the server side directly (not 302/303/307 response)
  • Rewrite the header of the response header of Content-Encoding, only if the client side send the header Accept-Encoding

This solution works on my IIS7, not sure if it will also work on IIS10.

If you met any problem, let me know :D

相关问答

更多

相关文章

更多

最新问答

更多
  • python的访问器方法有哪些
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。
  • 响应navi重叠h1和nav上的h1链接不起作用(Responsive navi overlaps h1 and navi links on h1 isn't working)
  • 在C中读取文件:“r”和“a +”标志的不同行为(Reading a File in C: different behavior for “r” and “a+” flags)
  • NFC提供什么样的带宽?(What Kind of Bandwidth does NFC Provide?)
  • 元素上的盒子阴影行为(box-shadow behaviour on elements)
  • Laravel检查是否存在记录(Laravel Checking If a Record Exists)
  • 设置base64图像的大小javascript - angularjs(set size of a base64 image javascript - angularjs)
  • 想学Linux 运维 深圳有哪个培训机构好一点
  • 为什么有时不需要在lambda中捕获一个常量变量?(Why is a const variable sometimes not required to be captured in a lambda?)
  • 在Framework 3.5中使用服务器标签<%=%>设置Visible属性(Set Visible property with server tag <%= %> in Framework 3.5)
  • AdoNetAppender中的log4net连接类型无效(log4net connection type invalid in AdoNetAppender)
  • 错误:发送后无法设置标题。(Error: Can't set headers after they are sent. authentication system)
  • 等待EC2实例重启(Wait for an EC2 instance to reboot)
  • 如何在红宝石中使用正则表达式?(How to do this in regex in ruby?)
  • 使用鼠标在OpenGL GLUT中绘制多边形(Draw a polygon in OpenGL GLUT with mouse)
  • 江民杀毒软件的KSysnon.sys模块是什么东西?
  • 处理器在传递到add_xpath()或add_value()时调用了什么顺序?(What order are processors called when passed into add_xpath() or add_value()?)
  • sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)
  • 如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)
  • AESGCM解密失败的MAC(AESGCM decryption failing with MAC)
  • SQL查询,其中字段不包含$ x(SQL Query Where Field DOES NOT Contain $x)
  • PerSession与PerCall(PerSession vs. PerCall)
  • C#:有两个构造函数的对象:如何限制哪些属性设置在一起?(C#: Object having two constructors: how to limit which properties are set together?)
  • 平衡一个精灵(Balancing a sprite)
  • n2cms Asp.net在“文件”菜单上给出错误(文件管理器)(n2cms Asp.net give error on Files menu (File Manager))
  • Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)
  • 湖北京山哪里有修平板计算机的