如何创建电子邮件回复/方法来编码回复?(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
最满意答案
更整洁优雅的解决方案:
注意:文件扩展名
.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 headerAccept-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
相关问答
更多-
成功! 问题是默认WebAPI模板web.config中的一行:
<-- BAD!!!! 我更新了我的package.json 添加了“eventemitter3”:“^ 0.1.6”并将grunt-connect-proxy的版本从0.1.6更新为0.2.0。 它对我有用 参考: github.com/drewzboto/grunt-connect-proxy/issues/97 I updated my package.json added "eventemitter3": "^0.1.6" and updated the version of grunt-connect-proxy fro ...更整洁优雅的解决方案: 注意:文件扩展名.gzip似乎很奇怪,一般来说,我们将一个gziped文件命名为.gz ,因此在本例中,如果您坚持使用.gzip ,则使用.gz而不是.gzip ,只需替换以下所有扩展名配置文件。 首先编码,这就是web.config所需的全部内容在Windows10 IIS10中注册.Net Framework 4.6 [复制](Register .Net Framework 4.6 in Windows10 IIS10 [duplicate])[2022-07-28]
您可以将您的项目托管在任何这些池中。 即使您的项目是使用.Net框架4.6构建的,这也可以正常工作 You can host your project under any of these pools. This will work fine even if you project is build with .Net framework 4.6静态文件夹的位置是错误的,它应该在imagenes文件夹的同一级别。 喜欢这个 my site/ imagenes/ setting.py imaagenes2/ #beacuse i dnt khow this floder name in your project views.py static/ css/ main.css js/ main.js 现在你可以把它设置为setting. ...问题是您的静态中间件设置,它指向错误的路径。 根据您评论中的信息: .js.gz文件存储在../public/assets/static/js/ 您正在请求/assets/static/js/bundle.js ,它应该在上述目录中使用名为bundle.js.gz的文件 这意味着您需要使用以下两种静态中间件配置之一: app.use('/assets', express.static(__dirname + '/../public/assets')); 要么: app.use(express.static ...正如你所看到的那样,还有一个开放的请求 ......无论如何设置默认的servletgzip true 有些内容会缓存页面,为了帮助您找出问题所在,您应该尝试访问新PC上的更新页面,最好是在单独的网络上从未访问过此网站。 如果您在单独的网络上看到新PC上的延迟相同,则可能是提供商配置。 如果网站在单独的PC和网络上正常加载,那么它可能是一个本地问题,一些企业系统可以做缓存来限制您的网络的网络成本,或者它可能只是您的浏览器缓存。 There is something caching the pages, To help find out where the issue could be, You should ...如何提供静态文件?(How to serve static files? (css))[2022-03-28]
Camping的当前(记得从RubyGems安装最新版本!)对静态文件的立场是服务器应该负责提供静态文件。 如果您使用camping -command,则应自动为您提供public/ -directory。 只需将cards.css移动到public/cards.css和localhost:3301 / cards.css即可返回该文件。 在生产中,您应该直接从public/ -directory配置Apache / Nginx /其他任何服务文件。 如果您无法配置Apache / Nginx(例如在Her ...提供gzip文件(Serve gzip files)[2022-10-15]
您应该可以执行以下操作...尝试看看是否有效: HttpResponseMessage response = new HttpResponseMessage(); response.Content = new StreamContent(File.OpenRead("Path-to-gzip-compressed-json-file")); response.Content.Headers.ContentEncoding.Add("gzip"); return response; You should ...相关文章
更多- English,The Da Vinci Code,Chapter 1-3
- Drupal Forums instead of phpBB or vBulletin: A casestudy
- 《wordpress插件制作视频教程》(How to create a wordpress plugin)全5集更新完毕[HDTV]
- reading notes for solr source code
- Create a Bootable MicroSD Card
- Hadoop源码分析HDFS ClientProtocol——create
- Solr: a custom Search RequestHandler
- A Great List of Windows Tools
- 《Joomla 2.5 模板教程:宁皓网》(Create a Joomla 2.5 Template)前两章 + 模板资源[光盘镜像]
- Hibernate 异常之:associate a collection with two ...
最新问答
更多- 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)
- 湖北京山哪里有修平板计算机的