PC Review Forums Newsgroups Microsoft Outlook Microsoft Outlook VBA Programming Junk Mail Filter macro

Reply

Junk Mail Filter macro

 
Thread Tools Rate Thread
Old 30-04-2004, 03:25 PM   #1
Freddy G
Guest
 
Posts: n/a
Default Junk Mail Filter macro


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.


  Reply With Quote
Old 30-04-2004, 03:41 PM   #2
Sue Mosher [MVP-Outlook]
Guest
 
Posts: n/a
Default Re: Junk Mail Filter macro

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.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx


"Freddy G" <anonymous@discussions.microsoft.com> wrote in message
news:686e01c42ebe$ed8e81e0$a401280a@phx.gbl...
> 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.
>
>



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off