manipulating outlook 2003(not express) blocked senders list with vba - macro

S

shaik

hi
i am using microsoft outlook 2003 (not outlook express 2003) with 'use
cached exchange mode', on windows xp.and i want to manipulate blocked
senders list using a vba code (macro).
actually i want to extract all the email ids from blocked senders list and
then write it to an excel file, then delete all the mail ids of blocked
senders list and after some alterations i want to add mail address from
excel file to blocked senders list.
in brief i want to add,delete email addresses of blocked senders list using
vba code.
can u pls help me this regards
thank u very much for ur help.

shaik
 
S

Siegfried Weber

shaik said:
i am using microsoft outlook 2003 (not outlook express 2003) with 'use
cached exchange mode', on windows xp.and i want to manipulate blocked
senders list using a vba code (macro).
actually i want to extract all the email ids from blocked senders
list and then write it to an excel file, then delete all the mail ids
of blocked senders list and after some alterations i want to add mail
address from excel file to blocked senders list.
in brief i want to add,delete email addresses of blocked senders list
using vba code.

There is no documented API for that. So far I've been able to export the
lists using a quick piece of VBScript. They are stored in the registry plus
a hidden item in your inbox. I haven't figured out which one takes
precedence hence I don't know how to programmatically update those things.
Having said that, here's a piece to export such stuff:

Set objWSHShell = CreateObject("WScript.Shell")
varJunkMail = Array()
intCounter = 0
bstrJunkMailList = ""
strProfileName = "PST" ' Replace with the Outlook profile name
strRegValue = "HKEY_CURRENT_USER\Software\Microsoft\Windows
NT\CurrentVersion\Windows Messaging Subsystem\Profiles\" & strProfileName &
"\0a0d020000000000c000000000000046\001f0419"

' Note that the registry key is does not exist if no e-mail address has been
entered in Outlook 2003
' Also note that the content of the key is stored in UNICODE format and
needs to be converted
' Safe senders list: 001f0418
' Safe recipient list: 001f0419
' Blocked senders list: 001f041a

bstrJunkMailList = objWSHShell.RegRead(strRegValue)
If UBound(bstrJunkMailList) <> 0 Then
For intCounter = LBound(bstrJunkMailList) To UBound(bstrJunkMailList)
If Hex(bstrJunkMailList(intCounter)) <> 0 Then
strJunkMailList = strJunkMailList & Chr(bstrJunkMailList(intCounter))
Else
strJunkMailList = strJunkMailList & " "
End If
strJunkMailList = Left(strJunkMailList, InStr(1, strJunkMailList, " ") -
1)
strJunkMailList = Replace(strJunkMailList, " ", "")
Next
End If
varJunkMail = Split(strJunkMailList, ";")
For intCounter = LBound(varJunkMail) To UBound(varJunkMail)
If Trim(varJunkMail(intCounter)) <> "" Then
WScript.Echo varJunkMail(intCounter)
End If
Next

--
Cheers,

Siegfried Weber

If you want a smart answer, ask a smart question
http://catb.org/~esr/faqs/smart-questions.html

Why tables are bad: http://www.hotdesign.com/seybold/

Note: Please do not send any e-mail to (e-mail address removed) because I am
no longer connected with this organization. The current owner does not
return NDRs (non delivery reports - aka bounce messages) hence you will
not get any confirmation what happened to the e-mail.
 
K

Ken Slovak - [MVP - Outlook]

Sig - I found that setting the registry values didn't change what's shown in
the UI for blocked senders even after exiting and restarting Outlook. I
haven't played much with the hidden item and done any decoding of the binary
in it but that seems to be what's needed. YMMV.
 
S

Siegfried Weber

Ken said:
Sig - I found that setting the registry values didn't change what's
shown in the UI for blocked senders even after exiting and restarting
Outlook. I haven't played much with the hidden item and done any
decoding of the binary in it but that seems to be what's needed. YMMV.

Thanks Ken! That's what I expected. In an Exchange 2003 environment OWA uses
the same Junk mail lists as MAPI Outlook 2003 so I figure they both use the
hidden item too. I haven't had time to play with that but at least exporting
the lists out of the registry seems to work ;-)

--
Cheers,

Siegfried Weber

If you want a smart answer, ask a smart question
http://catb.org/~esr/faqs/smart-questions.html

Why tables are bad: http://www.hotdesign.com/seybold/

Note: Please do not send any e-mail to (e-mail address removed) because I am
no longer connected with this organization. The current owner does not
return NDRs (non delivery reports - aka bounce messages) hence you will
not get any confirmation what happened to the e-mail.
 
K

Ken Slovak - [MVP - Outlook]

Yeah, when you change the settings in the hidden message and the registry
are updated. Just change the registry and nothing happens with the hidden
message. Importing using the UI changes both also.
 
S

shaik

hi Sieg,
Thank u very much. it helped me a lot. i can read the list using ur code.
when i deleted the key from registry and restart the outlook it removes
blocked senders list.
can u pls help me how to add a blocked sender programatically (thats to the
registry).i want to add 100s of mail addresses to blocked senders list
programatically and also to delete the entire list .
once again thanks for ur help.
best wishes
n. shaik
 
S

Siegfried Weber

shaik said:
Thank u very much. it helped me a lot. i can read the list using ur
code. when i deleted the key from registry and restart the outlook it
removes blocked senders list.
can u pls help me how to add a blocked sender programatically (thats
to the registry).i want to add 100s of mail addresses to blocked
senders list programatically and also to delete the entire list .
once again thanks for ur help.

See Kens reply. I haven't had any chance to try and *import* stuff into
those Outlook 2003 lists but as Ken indicates it appears not to be possible
(at least without hacking the unicode decoded hidden mail Outlook 2003 uses
too to store the lists).

--
Cheers,

Siegfried Weber

If you want a smart answer, ask a smart question
http://catb.org/~esr/faqs/smart-questions.html

Why tables are bad: http://www.hotdesign.com/seybold/

Note: Please do not send any e-mail to my old address (e-mail address removed)
because I am
no longer connected with this organization.
 
K

Ken Slovak - [MVP - Outlook]

You don't display a hidden message, that's why it's hidden. Besides, the
contents are an undocumented binary so displaying it would do no good. You
can see things if you use OutlookSpy (www.dimastr.com) but unless you figure
out how to decode it just looking at it won't do any good.

I don't know of a way to do the import using code. If we could figure out
the binary then there might be a shot at it.




JRock said:
How do you display the hidden message? Also, do you all know of a way to
programatically import a junk senders text file? I have written a macro
that I can use to add junk sender domain names to a text file, however I
don't know how to import the text file.
 
Joined
Jun 19, 2009
Messages
1
Reaction score
0
Hello Everyone,

The following AutoIt script will allow you to add Domains to the safe sender list.


AutoIt Version: 3.3.0.0
Author: Outlook WhiteList - Max Albanese
Script Function:
Adds @domain1.net and @domain2.com to the Outlook Whitelist
#ce ----------------------------------------------------------------------------
AutoItSetOption("TrayIconHide",1)
#include
_FileWriteLog(@TempDir & "\outlwl.log","Starting Outlook Whitelist Script.",-1)
_FileWriteLog(@TempDir & "\outlwl.log","Checking Default EMail Profile.",-1)
$DefaultMailProf = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles","DefaultProfile")
If @error <> 0 Then
Select
Case @error = -1
_FileWriteLog(@TempDir & "\outlwl.log","Error: Unable to Open Requested Key." ,-1)
Case @error = 2
_FileWriteLog(@TempDir & "\outlwl.log","Error: Unable to Open Requested Main Key." ,-1)
Case @error = 3
_FileWriteLog(@TempDir & "\outlwl.log","Error: Unable to Remote Connect to the Registry." ,-1)
Case @error = --1
_FileWriteLog(@TempDir & "\outlwl.log","Error: Unable to Open Requested Value." ,-1)
Case @error = -2
_FileWriteLog(@TempDir & "\outlwl.log","Error: Value Type Not Supported" ,-1)
Case Else
_FileWriteLog(@TempDir & "\outlwl.log","Error: Unknown Remote Registry Error." ,-1)
EndSelect
_FileWriteLog(@TempDir & "\outlwl.log","Error: Exiting Script." ,-1)
Exit
EndIf
_FileWriteLog(@TempDir & "\outlwl.log","Default Profile: " & $DefaultMailProf ,-1)
_FileWriteLog(@TempDir & "\outlwl.log","Reading Existing WhiteList from the registry.",-1)
$var = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\" & $DefaultMailProf & "\0a0d020000000000c000000000000046","001f0418")
$write = ""
_FileWriteLog(@TempDir & "\outlwl.log","Changing Whitelist from Binary to String.",-1)
$btost = BinaryToString($var,2)
_FileWriteLog(@TempDir & "\outlwl.log","Current WhiteList: " & $btost,-1)
_FileWriteLog(@TempDir & "\outlwl.log","Searching for items already in the whitelist.",-1)
_FileWriteLog(@TempDir & "\outlwl.log","Searching for @global.umusic.net",-1)
If StringInStr($btost,"@domain1.net",2,1) Then ;Change this line to your domain name you want to add
_FileWriteLog(@TempDir & "\outlwl.log","@domain1.net already found. Checking that it is domain whitelist.",-1)
$pos = 0
$pos = StringInStr($btost,"@domain1.net",2,1) ;Same here
If $pos = 1 Then
_FileWriteLog(@TempDir & "\outlwl.log","Verified Domain Whitelist @domain1.net",-1)
Else
If StringInStr($btost,";@domain1.net",2,1) Then
_FileWriteLog(@TempDir & "\outlwl.log","Verified Domain Whitelist @domain1.net",-1)
Else
$write = "@domain1.net;"
_FileWriteLog(@TempDir & "\outlwl.log","Not a domain entry but a single e-mail. Adding to write queue.",-1)
EndIf
EndIf
Else
$write = "@domain1.net;"
_FileWriteLog(@TempDir & "\outlwl.log","Entry not found. Adding to write queue.",-1)
EndIf
_FileWriteLog(@TempDir & "\outlwl.log","Searching for @domain2.com",-1)
If StringInStr($btost,"@domain2.com",2,1) Then
_FileWriteLog(@TempDir & "\outlwl.log","@domain2.com already found. Checking that it is domain whitelist.",-1)
$pos = 0
$pos = StringInStr($btost,"@domain2.com",2,1)
If $pos = 1 Then
_FileWriteLog(@TempDir & "\outlwl.log","Verified Domain Whitelist @domain2.com",-1)
Else
If StringInStr($btost,";@domain2.com",2,1) Then
_FileWriteLog(@TempDir & "\outlwl.log","Verified Domain Whitelist @domain2.com",-1)
Else
$write = $write & "@domain2.com;"
_FileWriteLog(@TempDir & "\outlwl.log","Not a domain entry but a single e-mail. Adding to write queue.",-1)
EndIf
EndIf
Else
$write = $write & "@domain2.com;"
_FileWriteLog(@TempDir & "\outlwl.log","Entry not found. Adding to write queue.",-1)
EndIf
If $write <> "" Then
$write = $write & $btost
_FileWriteLog(@TempDir & "\outlwl.log","Adding " & $write & " to the Whitelist.",-1)
_FileWriteLog(@TempDir & "\outlwl.log","Converting from String to Binary.",-1)
$sttob = StringToBinary($write,2)
$var = RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\" & $DefaultMailProf & "\0a0d020000000000c000000000000046","001f0418","REG_BINARY",$sttob)
Else
_FileWriteLog(@TempDir & "\outlwl.log","Nothing to update. See above.",-1)
EndIf
_FileWriteLog(@TempDir & "\outlwl.log","Exiting Program. ",-1)

This will add the domains domain1.net and domain2.com to the whitelist. My only problem with this is that once the whitelist is updated it does not update to the server. That I am still trying to work out. This works on both Office 2003 and Office 2007.

Any ideas,

Max
MCSE,MCSA,MCSAM
 
Last edited:
Joined
May 9, 2010
Messages
1
Reaction score
0
... and now with the coming Office 2010 ... those registry keys no longer appear to exist. Microsoft must have invented a new place to store this information. Guess that's my fault for having just created a bunch of VBA macros to manipulate the blocked senders list!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top