Link to home
Start Free TrialLog in
Avatar of blarts
blarts

asked on

how can I block all emails with html content

I want to filter out all msgs that I receive in outlook 2000 that have html as the body, as these are invariably junk.
ie. Any msgs that are ordainary text, allow into inbox
    any msgs with html as the body text, move to junk folder

Any ideas on how I might do this?

Cheers
Duncan
Avatar of Neo_mvps
Neo_mvps

I would probably go with a VBA macro/event sink that checks the length of the htmlbody propery and then moves the item.

For an example on how to convert a message from html to plain text can be found at http://www.slipstick.com/dev/code/zaphtml.htm (note: with a little modification of this code, it will solve the first paragraph.)
If you are not interested in vba coding, you can go third-party.  Pop Agent sounds like an interesting alternative for email purposes - http://www.imesoftware.com/popagent.htm
Avatar of blarts

ASKER

The VBA option sounds good, however I don't know how to set about doing this as my programming skills are on mainframes (old dinosaur that I am)
Any chance of an idiots step by step guide to inplementing a suitable macro?
Sure... this code is a bit weird because outlook isn't allowing me to move the original item.  so this code makes a copy and moves it to a folder named Junk Mail right under the inbox and then deletes the original.

steps for you...
* Press CTRL+F11
* Go to ThisOutlookSession and paste in the following


Option Explicit
Private WithEvents olInboxItems As Items

Private Sub Application_Startup()

  Dim objNS As NameSpace
  Set objNS = Application.GetNamespace("MAPI")
  ' instantiate objects declared WithEvents
  Set olInboxItems = _
    objNS.GetDefaultFolder(olFolderInbox).Items
  Set objNS = Nothing
End Sub

Private Sub Application_Quit()
  ' disassociate global objects declared WithEvents
  Set olInboxItems = Nothing
End Sub

Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
  Dim objFolder As Outlook.MAPIFolder
  Dim objTemp As Object
  ' On Error Resume Next

  If Item.HTMLBody <> vbNullString Then
    Set objFolder = _
      Application.Session.GetDefaultFolder(olFolderInbox)

    Set objFolder = objFolder.Folders.Item("Junk Mail")
    Set objTemp = Item.Copy
    Call objTemp.Move(objFolder)
    objTemp.Close (olSave)
    Item.Delete
  End If
  Set Item = Nothing
End Sub



I should mention this... this method can end up missing items to copy/delete.  there is a timing issue in outlook where it won't call the event for every message. so if you end up getting 20 or more items at once, expect the code to miss a few.
ASKER CERTIFIED SOLUTION
Avatar of tcav
tcav

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Nice suggestion about the rules wizard -- but it fails when running against a Microsoft Exchange server and the message comes from another person in the same site/org. (There is no internet header to search)
True.

But blarts wants to block junk mail (and so do I.) It's unlikely that he (I'm presuming blarts is male) would want to block an html message that originated from his own Exchange Server.
Avatar of blarts

ASKER

Many thanks mate, that seemed to work perfectly. (Yes I am male!)

Avatar of blarts

ASKER

Many thanks for your help Neo. I implemented the code but need to get the folders name sorted out. I'm quite keen to get the hang of VBA coding so I'll be having a close look at the code you kindly sent me when I get back from holiday.
In the meantime the rules wizard solution seems to be working fine for what I need. I'd like to be able to show my appreciation for your help with points/grade but don't seem to be able to do so now having accepted tcav's answer. For what its worth, I thought it was A1. Cheers!