问题描述
当一条消息得到回复或转发时,前一个线程会附加到您的新邮件中,方法是将 ----Original Message---- 放在它前面.
When a message gets replied or forwared the previous thread gets appended on your new mail by placing i.e. ----Original Message---- in front of it.
Outlook 对 tekst 消息执行相同的操作,但对于 HTML 邮件,它显示一行后跟 From:...
Outlook does the same with tekst messages but with HTML mails it shows a line followed with From:..
由于 Outlook 在这些消息之间显示了一条线,我相信可以使用 VBA 减去这些消息.但是如何?
Since outlook shows a line in between these messages i believe it's possible to subtract these messages using VBA. But How?
目标:当用户发送邮件 (Application_ItemSend) 时,我想扫描邮件中的某些词.但我不在乎它是否出现在以前的消息中,我只想扫描新输入的消息.
Goal: When the user sends a mail (Application_ItemSend) I want to scan the message for certain words. But I don't care if it occurs in a previous message, i only want to scan the newly typed message.
以下示例适用于在 Outlook 中回复文本形式的电子邮件(Outlook 是英文的!).但是在发送 HTML 电子邮件时它不起作用.
The example below will work when answering an email in outlook when it's in text (and outlook is in english!). But it will NOT work when sending a HTML email.
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim EndOfMsg As Integer
Dim myMsg as String
EndOfMsg = InStr(Item.Body, "-----Original Message-----")
If EndOfMsg = 0 Then
myMsg = Item.Body
Else
myMsg = Left(Item.Body, EndOfMsg)
End If
MsgBox myMsg
End Sub
所以我需要一些令牌"来拆分,正确..但是这个令牌是什么?myMsg 和旧的 msg 之间只有一个双 vbCrLf
.与我在消息中输入新行时相同.. 没有任何独特之处!
So i need some 'token' to split on, correct.. But what is this token? All there is between myMsg and the older msg's is a double vbCrLf
. The same as when i enter a new line in my message.. no nothing at all unique!
推荐答案
答案取决于用户是发送 HTML 还是富文本电子邮件.(这通常取决于他们是以 HTML 还是 RTF 格式回复/转发邮件,除非他们手动更改格式.)
The answer depends on whether the user is sending HTML or rich text email. (This will usually depend on whether they are replying to/forwarding a message in HTML or RTF, unless they manually change the format.)
在任何一种情况下,您都需要查找指示您感兴趣的消息结尾的模式,然后停在那里.使用 Instr()
确定您需要停止的位置.然后,当您解析文本以查找某些单词"时,请跟踪您阅读了多少个字符,并在到达标记处时停止.
In either case, you need to look for a pattern that indicates the end of the message you are interested in, and stop there. Use Instr()
to identify where you need to stop. Then, as you are parsing the text looking for your "certain words", keep track of how many characters you have read and stop when you get to the marker.
富文本
在 Item.Body
中查找^p^p__________________________^p".
Look in Item.Body
for "^p^p__________________________ ^p".
那是 2 个 VbCrLf 实例,46 个 Chr(95) 实例,一个空格,然后是另一个 VbCrLf 实例.
That's 2 instances of VbCrLf, 46 instances of Chr(95), a space, and then another instance of VbCrLf.
HTML
在 Item.Body
中,标记为^p _ ^p".
In Item.Body
, the token is "^p _ ^p".
这是一个 VbCrLf、2 个空格、5 个 Chr(95) 实例、另外 2 个空格和另一个 VbCrLf.
That's one VbCrLf, 2 spaces, 5 instances of Chr(95), 2 more spaces, and another VbCrLf.
在Item.HTMLBody
中,token是
<DIV dir=ltr lang=en-us class=OutlookMessageHeader align=left>
<HR tabIndex=-1>
该标记之前、两行之间和末尾有一个 VbCrLf.
That token has a VbCrLf before it, between the two lines, and at the end.
这篇关于在电子邮件对话正文中检测新消息的结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!