如何在发送前删除电子邮件正文中的文本? [英] How do I remove text in the body of an email before send?

查看:118
本文介绍了如何在发送前删除电子邮件正文中的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们公司会对来自外部来源的任何传入电子邮件发出通知,以警告我们在打开附件或点击链接时要小心谨慎.保证?是的.恼人的?是的.看起来有点不专业?也许吧.

Our company puts a notice on any incoming email from an outside source to warn us to exercise caution when opening attachments or clicking on links. Warranted? Yes. Annoying? Yes. Looks somewhat unprofessional? Maybe.

我尝试了几种不同的 VBA 迭代来询问我是否希望在发送时删除消息.我当前的代码在下面,它会显示消息框,所以我知道我的格式是正确的并且它找到了文本,但它实际上不会删除它.

I've tried several different iterations of VBA to ask if I want the message removed on send. My current code is below and it will bring up the message box, so I know that my formatting is correct and it finds the text, but it won't actually remove it.

Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim strBody As String

If InStr(Item.Body, "NOTICE: This email is from an external sender. Please exercise caution when opening attachments or clicking links.") > 0 Then
   If MsgBox("Do you want to remove the Notice?", vbYesNo) = vbYes Then
     strBody = Replace(Item.Body, "NOTICE: This email is from an external sender. Please exercise caution when opening attachments or clicking links.", "", vbTextCompare)

   Else
      strBody = Item.Body
   End If
End If

Item.Save
End Sub

我希望出现消息框并询问是否需要删除通知,如果我单击是,则将其删除,但将其他所有内容留在电子邮件中.一个警告是,如果这条通知是一条有多个回复的长链,则可能会有多个实例.如果我是链上唯一的一个,那么我的宏将删除之前回复中的任何内容,但如果其他人在链上并且不删除他们的,那么如果我回复,我希望我的宏执行此操作(我意识到我不能对别人做任何事情).

I would like for the message box to come up and ask if the notice needs to be removed and then remove it if I click yes, but leave everything else in the email alone. One caveat is that there could be multiple instances of this notice if it's a long chain with multiple replies. If I'm the only one on the chain then my macro will have removed any in prior replies, but if others are on the chain and don't remove theirs then I'd like my macro to do it if I reply (I realize I can't do anything about others).

如果是 HTML 电子邮件与纯文本,代码是否需要有所不同?

Would the code need to be any different if it's an HTML email versus plain text?

这是我当前的代码.我已经让它删除了通知,现在它不会删除新电子邮件,但发送回复真的很慢.

Here's my current code. I've got it to remove the notice and it now will not delete a new email, but the send on a reply is really slow.

Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

Dim strBody As String

If InStr(Item.HTMLBody, "LHMSE NOTICE: This email is from an external sender. Please exercise caution when opening attachments or clicking links.") > 0 Then
   If MsgBox("Do you want to remove the LHMSE Notice?", vbYesNo) = vbYes Then
     strBody = Replace(Item.HTMLBody, "LHMSE NOTICE: This email is from an external sender. Please exercise caution when opening attachments or clicking links.", "", vbTextCompare)
     Item.HTMLBody = strBody

   Else
      strBody = Item.HTMLBody
   End If
End If

Item.Save
End Sub

推荐答案

您永远不会将 Item.Body 属性设置回存储在 strBody 变量中的新值.还要记住,您将清除格式,因为您正在处理纯文本正文而不是 MailItem.HTMLBody.

You never set the Item.Body property back with the new value stored in the strBody variable. Also keep in mind that you will wipe out the formatting since you are dealing with the plain text body rather than MailItem.HTMLBody.

这篇关于如何在发送前删除电子邮件正文中的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆