adding at once all the email addresses of the spammers in the list of unwanted /unsollicited mails

S

Spectre

Hi,

Even if spammers use often a new address for each spam they send, it is not
always the case.

Hence, I am looking for a function which could add on one click all the
email addresses of the spams beeing in the unsollicited email folder (a
translation from French for "courrier indésirable")! to the list of
unsollicited mail addresses.
I have tried to do it myself but I have been unable to find the name of this
list.

Thanks
 
G

Guest

For versions prior to 2003, Outlook stores the list of blocked senders in
this file:

C:\Documents and Settings\user\Application Data\Microsoft\Outlook\Junk
Senders.txt

However, if you have Outlook 2003 you are out of luck. Otherwise, all you
need to do is append e-mail addresses to this file. A good way is to use the
TextStream object from the Microsoft Scripting Runtime Library (VBScript).

To get a handle to the selected e-mail, use the Explorer.Selection property.
For an open e-mail, use Inspector.CurrentItem. In both cases, get the value
of the MailItem.SenderEmailAddress. Note that accessing this property will
cause the security warning dialog to appear. See this link for more info:

Microsoft Outlook "Object Model Guard" Security Issues for Developers:
http://www.outlookcode.com/d/sec.htm
 
M

Michael Bauer

Am Wed, 8 Mar 2006 11:44:37 +0100 schrieb Spectre:

Because you cannot add multiple items at once via CommandBars this could be
a workaround:

1. You do have all selected items in ActiveExplorer.Selection. Keep that
list.
2. Create an empty folder
3. Switch to that folder
4. Copy one item from your selection into that folder. The item should be
the selected one now.
5. Call the CommmandBarButton.Execute (e.g. ID 9786 in OL 2003 for the
button "Add to blocked senders")
6. Delete that item from the folder
7. Go on with step 4 as long as the list contains items
8. No you could delete the created folder or keep it for the next time
 
S

Spectre

hi,
thanks for your answers. I'll varry on with your ideas.

Bye


Spectre a pensé très fort :
 
S

Spectre

Well, I have found a solution which is not the most professionnal one,
but it works.

I use the Sendkeys function . Using a French release of outlook, the
Senkeys "letters" must be most probably changed.

Sub addSpamAdress() ' ajoute toutes les adresses des span à la liste
d'expéditeur indésirables
On Error Resume Next

Dim olItem As Mailitem
Dim objInbox As MAPIFolder
Dim oSelection
Dim arc As Outlook.MAPIFolder
Dim junkMailAddress As String

Set objNS = Application.GetNamespace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderJunk)
Set oSelection = objInbox.Items


For I = 1 To oSelection.Count
Set olItem = oSelection.Item(I)
If oSelection.Count <> 0 Then ' si il ya des mails
junkMailAddress = olItem.SenderEmailAddress
If junkMailAddress <> "" Then
' *******************************
SendKeys "%SSB" ' here the changes to do
' *******************************
End If
End If
Next
End Sub

Spectre a émis l'idée suivante :
 
S

Spectre

Better,
replace the Sendkeys line with :
Set Btn = Application.ActiveExplorer.CommandBars.FindControl(1, 9786)


Spectre a formulé la demande :
 
S

Spectre

Last release to add spam addresses in the list of blocked addresses. It
deletes also the spams.

Sub addSpamAdress() ' ajoute toutes les adresses des span à la liste
d'expéditeur indésirables
'On Error Resume Next

Dim olItem As Mailitem
Dim objInbox As MAPIFolder
Dim oSelection
Dim arc As Outlook.MAPIFolder
Dim junkMailAddress As String
Dim response As String

Set objNS = Application.GetNamespace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderJunk)
Set oSelection = objInbox.Items

response = MsgBox("Your are going to add all the email addresses
to the Bocked Email list" & vbCrLf & _
"All emails will be deleted",
vbYesNoCancel, "Junk Mail")

If response = vbNo Or response = vbCancel Then
Exit Sub
Else
For I = 1 To oSelection.Count
Set olItem = oSelection.Item(I)
If oSelection.Count <> 0 Then ' si il ya de s
mails
junkMailAddress = olItem.SenderEmailAddress
If junkMailAddress <> "" Then

Set Btn =
Application.ActiveExplorer.CommandBars.FindControl(1, 9786)
Btn.Execute
olItem.Delete

End If
End If
Next
End If
End Sub



Spectre a formulé la demande :
 
M

Michael Bauer

Am Sat, 11 Mar 2006 22:48:41 +0100 schrieb Spectre:

Unfortunately you´ve opened a new thread for the same topic. Please see my
answers in "last solution".
 
M

Michael Bauer

Am Sun, 12 Mar 2006 12:29:10 +0100 schrieb Spectre:

Did you test that solution also for the case that really several items are
selected?

As I wrote in your former thread, the button you refer to isn´t enabled if
more than one item is selected.

Additionally the For Next loop doesn´t work if you do have more than one
item in the list and delete them. In that case your loop must count
backwards:

For i=oSelection.Count To 1 Step -1
....
Next

No errors but hopefully useful tipps for you:
For I = 1 To oSelection.Count
Set olItem = oSelection.Item(I)
If oSelection.Count <> 0 Then ' si il ya de s
mails

If the loop starts, i.e. if the execution goes on with the last line, then
you do know already that Count said:
Set Btn =
Application.ActiveExplorer.CommandBars.FindControl(1, 9786)

The button is always the same. It slows down the execution if you set the
variable within the loop again and again.
 
S

Spectre

Hi,

Thanks for your comments and your help.

For sure the " If oSelection.Count <> 0 Then" is not necessary!
For the other points :
- i don't select all the items to delete but only one, and it works (it
adds all the adresses in the blocked list and deletes all the mails in
the directory) but... only if I have first deleted a email in the
"ordinary way" and I don't understand why.

If you can help me on this....

Thanks an dbye



Après mûre réflexion, Michael Bauer a écrit :
 
M

Michael Bauer

Am Tue, 14 Mar 2006 22:10:38 +0100 schrieb Spectre:

I must correct myself: In OL 2003 it doesn´t work to add more than one item
at once (at least not in the German version), but in OL XP it seems that it
does.

But you're using the SenderEMailAddress and that is a feature of OL 2003.
I'm really interested in what happens if you select more than one item.

So far I don't know why you do have to delete an item first. The CommandBar
trick only works if there's really one item selected - but sometimes none is
selected.
 
S

Spectre

Hi,
I should have mentionned that I am using outlook 2003.

The olItem.Delete must be, of course, positionned after the
Btn.execute.

So, trying to be clearer,
- if have added, at first, one of the spam address of one mail with
the usual command bar button, the code works correctly.

I just leave the focus on one of the spams or select several or all.
The focus can also be on Contacts or Calendar and the code runs
without any problem.

If I swap to another soft and go back to outlook it carries on to work.

- but if I try to launch the code withtout having before add one
address "manually" and whatever I selected (one or several or all
spams), I have and error "object variable or block variable with and
undefinied with"

Bye


Michael Bauer vient de nous annoncer :
 
M

Michael Bauer

Am Wed, 15 Mar 2006 13:34:41 +0100 schrieb Spectre:

Very interesting. On my machine(s) there´s no way to call the button´s
Execute if more than one mail is selected.

On which line do you get that error?
 
S

Spectre

I get the error on the "btn.Execute".

To keep you aupdate on the code...

Sub addSpamAdress() ' ajoute toutes les adresses des span à la liste
d'expéditeur indésirables
'On Error Resume Next

Dim olItem As Mailitem
Dim objInbox As MAPIFolder
Dim oSelection
Dim arc As Outlook.MAPIFolder
Dim junkMailAddress As String
Dim response As String

Set objNS = Application.GetNamespace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderJunk)
Set oSelection = objInbox.Items

response = MsgBox("Your are going to add all the email addresses
to the Bocked Email list" & vbCrLf & _
"All emails will be deleted",
vbYesNoCancel, "Junk Mail")

If response = vbNo Or response = vbCancel Then
Exit Sub
Else
For I = oSelection.Count To 1 Step -1
Set olItem = oSelection.Item(I)
junkMailAddress = olItem.SenderEmailAddress
If junkMailAddress <> "" Then

' SendKeys "%ssb" ID: 9786
Set btn =
Application.ActiveExplorer.CommandBars.FindControl(1, 9786)
btn.Execute

' Set btn =
Application.ActiveInspector.CommandBars.FindControl(1, 9786)
' btn.Execute
olItem.Delete
End If
Next
End If

Set objNS = Nothing
Set objInbox = Nothing
Set oSelection = Nothing
Set olItem = Nothing

End Sub



Michael Bauer a formulé la demande :
 
S

Spectre

By the way, I have microsoft CDO 1.21 and safeoutlook library as
references in the library .
Perhaps an explanation for the "bug" on your pc.

Bye


Michael Bauer a pensé très fort :
 
M

Michael Bauer

Am Thu, 16 Mar 2006 10:44:24 +0100 schrieb Spectre:

So the button isn´t found. It is available in mail folders only.
 
M

Michael Bauer

Am Thu, 16 Mar 2006 10:47:53 +0100 schrieb Spectre:

For sure that´s no reason. If I select more than one item the button is
disabled, I can´t enable it.
 
S

Spectre

Ok.

I don't have any issue when selecting several spams.

So today, I just add the address of one spam with the outlook menu and
and then use the code which works quickly.

If I don't do like this, the set btn returns "nothing" and this even if
I first add the adress with a Sendkeys, then cancel the sendkeys
command in the code and enable the set Btn command for the next spam.

If I can find a solution, I'll keep you posted.

Bye

Michael Bauer avait énoncé :
 

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