Junk Mail Filter macro

  • Thread starter Thread starter Freddy G
  • Start date Start date
F

Freddy G

I'm becoming overwhelmed with junk mail at work and I
found a helpful article on handling junk mail at
http://office.microsoft.com/assistance/preview.aspx?
AssetID=HA010429701033&CTT=4&Origin=CH010715451033
which basically talks about creating a macro to add
multiple selected emails to the junk senders list and then
delete them all in one shot.

Here is a sample of the code that is giving me grief:
'********************************************************
Set objTextStream = objFSO.OpenTextFile _
(FileName:=JUNK_SENDERS_FILE, IOMode:=ForAppending)

Set objExplorer = Application.ActiveExplorer

For Each objMailItem In objExplorer.Selection
objTextStream.WriteLine Text:=objMailItem.SenderName
objMailItem.Delete
Next objMailItem
'********************************************************

The problem I've come across is that in it's use of
the 'SenderName' property it is adding the name of the
person sending the email, instead of the e-mail address
itself. If I right-click an email and select 'Add to Junk
Senders List' then it will add the address as I want it
too, but the code above will add the person's name and it
won't be filtered properly in doing so.

Is there another property I can use in place
of 'SenderName' to extraxt the email address, or is there
a setting in Outlook 2002 which will display the email
address in the From column of the Inbox instead of the
person's name? The macro is a great idea but it's one
step away from where I need it to be and I would hate to
scrap it when it's so close to being right.

Thanks in advance,
Freddy G.
 
In Outlook 2003, you can use the MailItem.SenderEmailAddress, but note that
it's subject to security prompts.

In earlier versions, there is no Outlook property that returns the sender's
email address. You can either use CDO (or Redemption to avoid security
prompts -- http://www.dimastr.com/redemption/) to get the From address or
use Outlook to get the Reply To address. Sample code at
http://www.outlookcode.com/d/code/getsenderaddy.htm

FWIW, I consider this type of macro to be a pretty useless exercise since
the real problem spammers change addresses all the time. You'd be better off
investing in an effective anti-spam program.
 
Back
Top