简体   繁体   English

电子邮件有时会被扰乱

[英]Emails sometimes get scrambled

Folks, 伙计们,

I have a PHP-based site (using the QCubed framework ); 我有一个基于PHP的站点(使用QCubed框架 ); as a part of the site, I have a daemon that's sending out several thousand emails a day (no i'm not a spammer, everything is opt-in :)). 作为网站的一部分,我有一个守护进程,每天发送几千封电子邮件(不,我不是垃圾邮件发送者,一切都是选择加入:))。 Emails are sent through a custom framework component; 电子邮件通过自定义框架组件发送; that component serves as an SMTP client. 该组件充当SMTP客户端。 I'm using a paid SMTP gateway from DNSExit.com to get the emails actually delivered. 我正在使用DNSExit.com的付费SMTP网关来获取实际发送的电子邮件。

Those emails are simple HTML-based emails; 这些电子邮件是简单的基于HTML的电子邮件; they really have just simple links inside. 他们里面只有简单的链接。

My issue is that these links sometimes (not consistently!) get scrambled during transition. 我的问题是这些链接有时(不一致!)在转换期间被扰乱。 Tags somehow get mixed up, and some links are non-functional in the email. 标签以某种方式混淆,一些链接在电子邮件中不起作用。 The issue happens on a small percentage of all sent emails; 所有已发送电子邮件中的一小部分都会出现此问题; it is not consistent (ie the same exact source message HTML may or may not cause the scrambling in transition). 它不一致(即,相同的确切源消息HTML可能会或可能不会导致转换中的加扰)。

Have any of you seen this? 有没有人见过这个? Any thoughts on how to troubleshoot? 有关如何排除故障的任何想法?

Is it possible that you are using temp files to create the emails (or at minimum to create the variable content)? 您是否可能使用临时文件来创建电子邮件(或至少创建可变内容)? I did something vaguely similar once upon a time. 曾经做过一些模糊相似的事情。 The email text was generated and written to a temp file based on the exact time in seconds. 生成电子邮件文本并根据以秒为单位的确切时间将其写入临时文件。 Unfortunately, when sending thousands per day, we were hitting the same second more than once (since there are only 86k seconds available). 不幸的是,当每天发送数千个时,我们不止一次击中同一秒(因为只有86k秒可用)。 That might explain a) the small error rate and b) the apparent randomness. 这可能解释了a)小错误率和b)表观随机性。 For troubleshooting, I'd just see if the error rate increases with the number of emails and go from there. 对于故障排除,我只是看看错误率是否随着电子邮件数量的增加而增加。

I ran into a similar problem on a server running sendmail. 我在运行sendmail的服务器上遇到了类似的问题。

I was creating and testing an html email that would one day be mass mailed (opt-in, of course). 我正在创建和测试有一天会被大量邮寄的HTML电子邮件(当然,选择加入)。 I had myself a template for the email that was easy for any html programmer to read, but as such was heavy on the whitespace to line everything up correctly. 我有自己的电子邮件模板,任何html程序员都可以轻松阅读,但因此在空格上很重要,以便正确排列所有内容。 I thought to myself, if this is going to be mass emailed, after the template is rendered, I think I will minimize the whitespace in the file to save on space! 我想,如果要通过大量的电子邮件发送,在渲染模板之后,我想我会最小化文件中的空白以节省空间! So I created a brilliant regular expression to rid any unnecessary to send whitespace from the rendered email. 因此,我创建了一个精彩的正则表达式,以消除任何不必要的从呈现的电子邮件中发送空白。

Upon sending the email to myself, I opened the email and was baffled when I saw that some of the css and html were not showing up correctly, when my previous emails prior to my regexp were. 在发送电子邮件给我自己的时候,我打开了电子邮件,当我看到一些css和html没有正确显示时,当我之前在我的regexp之前发送的电子邮件时,我感到很困惑。 By looking at the original message I noticed that every once in a while, an exclamation mark (!) was appearing seemingly randomly throughout the message, thus breaking any css and html that came in its random path. 通过查看原始消息,我注意到每隔一段时间,感叹号(!)在整个消息中看起来似乎是随机的,从而打破了随机路径中出现的任何css和html。

Turns out that sendmail doesn't like it if a line in your email gets too long without a line break. 事实证明,如果电子邮件中的一行没有换行,那么sendmail就不会喜欢它。 When the line does get too long, sendmail will insert an exclamation mark followed by a line break right then and there, just to confuse and confound you. 当线路确实变得太长时,sendmail会插入一个感叹号,然后在那里插入换行符,只是为了混淆和混淆你。

Why did it not just choose a space between words to line break? 为什么不只是选择单词之间的空格换行? Why insert the exclamation mark? 为什么插入感叹号? Questions I'm afraid, without answers. 问题我害怕,没有答案。

My solution? 我的解决方案

sudo apt-get remove sendmail
sudo apt-get install exim4

I was having other problems with sendmail like it taking a full 60 seconds to send an email and exim4 just worked and I have never had to think about it again. 我遇到了sendmail的其他问题,比如花了整整60秒发送一封电子邮件,exim4刚刚工作,我再也没想过了。

If your mail server is using sendmail, this very well could be the problem, if not, thank you for letting me share my story with you. 如果您的邮件服务器使用的是sendmail,这很可能就是问题所在,如果没有,感谢您让我与您分享我的故事。 I needed to vent. 我需要发泄。

When you're sending email you should encode it so every line in the message body is not longer then 76 characters. 当您发送电子邮件时,您应对其进行编码,以便邮件正文中的每一行不超过76个字符。 You could use base64 for this but most systems use the quoted-printable encoding for text because it generates smaller messages. 您可以使用base64,但大多数系统对文本使用quoted-printable编码,因为它会生成较小的消息。 Base64 is usually only used for binary data. Base64通常仅用于二进制数据。

The problem is that HTML is not compatible with email. 问题是HTML与电子邮件不兼容。 That is why I created Mail Markup Language . 这就是我创建邮件标记语言的原因

HTML was created to operate with the HTTP protocol as those two technologies were invented by the same person at about the same time. 创建HTML是为了使用HTTP协议进行操作,因为这两种技术几乎是由同一个人在同一时间发明的。 The difference is that HTTP is a single session one way transfer from a server to a client. 不同之处在于HTTP是从服务器到客户端的单一会话单向传输。 That never changes as the HTML document always originates on a server, is sent to a requesting client, and once the transfer completes the connection between the client and server is dropped. 这种情况永远不会随着HTML文档始终在服务器上发生而发生变化,而是发送到请求客户端,一旦传输完成,客户端和服务器之间的连接就会被删除。

Email does not behave in such a way. 电子邮件不会以这种方式运行。 In email a communication originates at a client, is sent to one or more email serves, and then terminates at a distant client. 在电子邮件中,通信始发于客户端,发送到一个或多个电子邮件服务,然后终止于远程客户端。 The biggest difference, however, is that the document does not die with finality of a single transmission instance as is the case with a document transfer over HTTP. 然而,最大的区别在于文档不会像单个传输实例的终结一样死亡,就像HTTP上的文档传输一样。 A document sent in SMTP can be replied to, forwarded, or copied to multiple unrequested users. 在SMTP中发送的文档可以被回复,转发或复制到多个未请求的用户。 This one difference is profound when consideration for an email thread is considered. 当考虑考虑电子邮件线程时,这一区别是深刻的。

The problem is that SMTP and HTTP are different as demonstrated in the prior two paragraphs. 问题是SMTP和HTTP是不同的,如前两段所示。 This differences is compounded in that SMTP and HTTP have radically different formatting methods for the creation of header data. 这种差异更加复杂,因为SMTP和HTTP具有完全不同的格式化方法,用于创建标题数据。 HTML has header data that is intended to be compatible with the headers of HTTP transmissions and offer no compliance to SMTP transmissions. HTML具有标头数据,旨在与HTTP传输的标头兼容,并且不提供对SMTP传输的遵从性。 The HTML headers also do not account for the complexity of an email thread. HTML标头也不考虑电子邮件线程的复杂性。

The problem is exemplified when email software corrupts a HTML document to add formatting changes necessary to fit the conforming demands of that software and to also write header data directly into the document. 当电子邮件软件破坏HTML文档以添加必要的格式更改以适应该软件的符合要求并且还将标题数据直接写入文档时,就会例证该问题。 This exemplification becomes extremely pronounced when an HTML email becomes an email thread. 当HTML电子邮件成为电子邮件线程时,此示例变得非常明显。 Since the HTML header data has no method to account for the complexities of an email thread there is no way to supply relevant presentation definitions from a stylesheet that survive the transfer of the document. 由于HTML标题数据没有方法来解释电子邮件线程的复杂性,因此无法从传输文档的样式表中提供相关的表示定义。 Each time a HTML document, or a document with HTML formatting, is sent from one email software to another the document is corrupted and each email software device corrupts the prior corruption. 每次将HTML文档或具有HTML格式的文档从一个电子邮件软件发送到另一个电子邮件软件时,文档都会损坏,并且每个电子邮件软件设备都会破坏先前的损坏。 Email processing software may refer to either an email client, which certainly will corrupt a document, or an email server, that may only likely corrupt an email document. 电子邮件处理软件可以指电子邮件客户端,其肯定会破坏文档,或者电子邮件服务器,其可能仅可能损坏电子邮件文档。

The solution to the problem is to create a markup language convention that recognizes the requirements of email header data directly. 该问题的解决方案是创建一个标记语言约定,直接识别电子邮件标题数据的要求。 Those requirements are defined in RFC 5321 for the SMTP protocol and RFC 5322 for the client processing. 这些要求在RFC 5321中针对SMTP协议定义,而RFC 5322针对客户端处理定义。 The only way to properly extend this solution to account for the complexities of an email thread are to provide a convention for a multi-agent DOM. 正确扩展此解决方案以解决电子邮件线程的复杂性的唯一方法是为多代理DOM提供约定。

Paragraphs deleted due to technical inaccuracy and difference between the term multi-agent DOM and the nature of an invented feature not mentioned here even prior to the edit. 由于技术不准确以及术语多智能体DOM与此处未在编辑之前未提及的发明特征的性质之间的差异而删除了段落。

EDIT: a multi-agent DOM applies some degree of hierarchy, which may not be necessary to represent an email thread. 编辑:多代理DOM应用某种程度的层次结构,这可能不是表示电子邮件线程所必需的。

Had 2 problems with email data - usually "?" 电子邮件数据有2个问题 - 通常是“?” symbol somehow got inside some words, another was UTF and title related. 符号不知何故进入了一些词,另一个是UTF和标题相关。 First got "fixed" by changing hosting provider (so it was mail-server related) second one got fixed by changing PHPmailer library. 首先通过更改托管服务提供商来“修复”(因此它与邮件服务器相关)第二个通过更改PHPmailer库得到修复。

Try to specify how exactly data is scrambled. 尝试指定数据加密的准确程度。

Have you any special attributes in your links? 您的链接中有任何特殊属性吗? May be title attribute with not escaped quotes inside? 里面没有转义引号可能是title属性?

Something like this: <a href="http://some.site" title="My "correct" link">Link</a> 这样的事情: <a href="http://some.site" title="My "correct" link">Link</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM