A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Check receiver of incoming emails



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old January 26th 07, 06:30 AM posted to microsoft.public.outlook.program_vba
Veerle
external usenet poster
 
Posts: 1
Default Check receiver of incoming emails

Hi,

I would like to create a rule in outlook that moves all the incoming
emails (or emails in my inbox) for which the receiver's emailaddress is
not in a certain list to the spam folder. This is because we have a
domainname veerle-en-koen.be, but only use like 4 emailaddress of this
domainname and we get lots of spam to the other emailaddresses of this
domain like , , ...
The reason is that the company where we registered our domainname
forwards all the mail of the domain. So I would like to check the
receiver(s) of the incoming mails to see if one of our 4 really used
emailaddresses are in it, and if not: move the mail to the spam folder.

But I don't think this is possible with the rules of outlook. So now
the real question: I could write something in VBA that does this check,
but how can I make sure this VBA script is automaticcaly executed each
time new email arrives? If I could get an extra button on one of the
outlook toolbars that executes the script when pressed and parses all
the emails in the inbox would be fine as well, is that possible?

Veerle

Ads
  #2  
Old January 26th 07, 05:56 PM posted to microsoft.public.outlook.program_vba
Eric Legault [MVP - Outlook]
external usenet poster
 
Posts: 830
Default Check receiver of incoming emails

If you wanted to handle this, you'd need to write a VBA macro to trap the
ItemAdd event for the Inbox folder that is referenced by a MAPIFolder object
whose Items collection has been globally declared using With Events in the
ThisOutlookSession module, and set during the Application_Startup event.
However, Outlook will need to be running all the time, and the ItemAdd is not
*guaranteed* to fire if many messages are delivered/copied/moved at once
(usually greater than 16).

If you need a perfect solution that will run on the server side and does not
require Outlook to be running, and that is guaranteed to fire on all incoming
mail, you have to write an Exchange Event Sink. For more info on that, see:

Microsoft Exchange Server Development Technologies:
http://www.outlookcode.com/d/exstech.htm

You can also ping me offline, as I know event sinks very well.

I've included the starter code below to start you on your path. All you
need to do is add the code to check the sender’s e-mail address against
another list and move it to your spam folder if it matches.

Option Explicit
Dim WithEvents NewMailItems As Outlook.Items

Private Sub Application_Startup()
Set NewMailItems =
Application.GetNamespace("MAPI").GetDefaultFolder( olFolderInbox).Items
End Sub

Private Sub NewMailItems_ItemAdd(ByVal Item As Object)
'THIS WILL FIRE FOR EVERY NEW E-MAIL; YOU CAN USE THE
'Item OBJECT TO WORK WITH THE PROPERTIES OF THE E-MAIL MESSAGE
Dim objMail As Outlook.MailItem
If Item.Class olmail Then Exit Sub
Set objMail = Item
'Now you can do someting with the e-mail
End Sub

Private Sub Application_Quit()
Set NewMailItems = Nothing
End Sub

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Veerle" wrote:

Hi,

I would like to create a rule in outlook that moves all the incoming
emails (or emails in my inbox) for which the receiver's emailaddress is
not in a certain list to the spam folder. This is because we have a
domainname veerle-en-koen.be, but only use like 4 emailaddress of this
domainname and we get lots of spam to the other emailaddresses of this
domain like , , ...
The reason is that the company where we registered our domainname
forwards all the mail of the domain. So I would like to check the
receiver(s) of the incoming mails to see if one of our 4 really used
emailaddresses are in it, and if not: move the mail to the spam folder.

But I don't think this is possible with the rules of outlook. So now
the real question: I could write something in VBA that does this check,
but how can I make sure this VBA script is automaticcaly executed each
time new email arrives? If I could get an extra button on one of the
outlook toolbars that executes the script when pressed and parses all
the emails in the inbox would be fine as well, is that possible?

Veerle


  #3  
Old January 27th 07, 11:42 AM posted to microsoft.public.outlook.program_vba
Reiner Block
external usenet poster
 
Posts: 1
Default Check receiver of incoming emails

I guess it seems that it depends on the version.

I've written at Outlook 2003 on event NewMail, that adds a user field to each new mail which holds the receiving date. But with Outlook 2007 it does not work anymore. I even tried it with ItemAdd but both fails in the case you've rules that moves the new e-mails in other folders.

It seems that Outlook 2007 now first handles the rules before the events of the inbox folder can be fired. :-( Outlook 2003 first fired the event and then executed the rules.

Sighing greetings

Reiner

Eric Legault [MVP - Outlook] erklärte :
If you wanted to handle this, you'd need to write a VBA macro to trap the
ItemAdd event for the Inbox folder that is referenced by a MAPIFolder object
whose Items collection has been globally declared using With Events in the
ThisOutlookSession module, and set during the Application_Startup event.
However, Outlook will need to be running all the time, and the ItemAdd is not
*guaranteed* to fire if many messages are delivered/copied/moved at once
(usually greater than 16).

If you need a perfect solution that will run on the server side and does not
require Outlook to be running, and that is guaranteed to fire on all incoming
mail, you have to write an Exchange Event Sink. For more info on that, see:

Microsoft Exchange Server Development Technologies:
http://www.outlookcode.com/d/exstech.htm

You can also ping me offline, as I know event sinks very well.

I've included the starter code below to start you on your path. All you
need to do is add the code to check the sender’s e-mail address against
another list and move it to your spam folder if it matches.

Option Explicit
Dim WithEvents NewMailItems As Outlook.Items

Private Sub Application_Startup()
Set NewMailItems =
Application.GetNamespace("MAPI").GetDefaultFolder( olFolderInbox).Items
End Sub

Private Sub NewMailItems_ItemAdd(ByVal Item As Object)
'THIS WILL FIRE FOR EVERY NEW E-MAIL; YOU CAN USE THE
'Item OBJECT TO WORK WITH THE PROPERTIES OF THE E-MAIL MESSAGE
Dim objMail As Outlook.MailItem
If Item.Class olmail Then Exit Sub
Set objMail = Item
'Now you can do someting with the e-mail
End Sub

Private Sub Application_Quit()
Set NewMailItems = Nothing
End Sub

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/

"Veerle" wrote:

Hi,

I would like to create a rule in outlook that moves all the incoming
emails (or emails in my inbox) for which the receiver's emailaddress is
not in a certain list to the spam folder. This is because we have a
domainname veerle-en-koen.be, but only use like 4 emailaddress of this
domainname and we get lots of spam to the other emailaddresses of this
domain like , , ...
The reason is that the company where we registered our domainname
forwards all the mail of the domain. So I would like to check the
receiver(s) of the incoming mails to see if one of our 4 really used
emailaddresses are in it, and if not: move the mail to the spam folder.

But I don't think this is possible with the rules of outlook. So now
the real question: I could write something in VBA that does this check,
but how can I make sure this VBA script is automaticcaly executed each
time new email arrives? If I could get an extra button on one of the
outlook toolbars that executes the script when pressed and parses all
the emails in the inbox would be fine as well, is that possible?

Veerle


--
Reiner
--

"Wer fragt, ist ein Narr für fünf Minuten. Wer nicht fragt, bleibt ein Narr
für immer." Chinesische Weisheit
"Erfolg hat, wer ihm entgegengeht, statt ihm nachzulaufen." Onassis,
Aristoteles


  #4  
Old January 28th 07, 02:23 AM posted to microsoft.public.outlook.program_vba
Eric Legault [MVP - Outlook]
external usenet poster
 
Posts: 830
Default Check receiver of incoming emails

It has never been documented who wins between NewMail events and Outlook
rules, nor should you rely on either to occur in a determined order - for
*all* Outlook versions. If you want to win this battle you need to create an
Exchange Event Sink, which always fires first.

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Reiner Block" wrote:

I guess it seems that it depends on the version.

I've written at Outlook 2003 on event NewMail, that adds a user field to each new mail which holds the receiving date. But with Outlook 2007 it does not work anymore. I even tried it with ItemAdd but both fails in the case you've rules that moves the new e-mails in other folders.

It seems that Outlook 2007 now first handles the rules before the events of the inbox folder can be fired. :-( Outlook 2003 first fired the event and then executed the rules.

Sighing greetings

Reiner

Eric Legault [MVP - Outlook] erklärte :
If you wanted to handle this, you'd need to write a VBA macro to trap the
ItemAdd event for the Inbox folder that is referenced by a MAPIFolder object
whose Items collection has been globally declared using With Events in the
ThisOutlookSession module, and set during the Application_Startup event.
However, Outlook will need to be running all the time, and the ItemAdd is not
*guaranteed* to fire if many messages are delivered/copied/moved at once
(usually greater than 16).

If you need a perfect solution that will run on the server side and does not
require Outlook to be running, and that is guaranteed to fire on all incoming
mail, you have to write an Exchange Event Sink. For more info on that, see:

Microsoft Exchange Server Development Technologies:
http://www.outlookcode.com/d/exstech.htm

You can also ping me offline, as I know event sinks very well.

I've included the starter code below to start you on your path. All you
need to do is add the code to check the sender’s e-mail address against
another list and move it to your spam folder if it matches.

Option Explicit
Dim WithEvents NewMailItems As Outlook.Items

Private Sub Application_Startup()
Set NewMailItems =
Application.GetNamespace("MAPI").GetDefaultFolder( olFolderInbox).Items
End Sub

Private Sub NewMailItems_ItemAdd(ByVal Item As Object)
'THIS WILL FIRE FOR EVERY NEW E-MAIL; YOU CAN USE THE
'Item OBJECT TO WORK WITH THE PROPERTIES OF THE E-MAIL MESSAGE
Dim objMail As Outlook.MailItem
If Item.Class olmail Then Exit Sub
Set objMail = Item
'Now you can do someting with the e-mail
End Sub

Private Sub Application_Quit()
Set NewMailItems = Nothing
End Sub

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/

"Veerle" wrote:

Hi,

I would like to create a rule in outlook that moves all the incoming
emails (or emails in my inbox) for which the receiver's emailaddress is
not in a certain list to the spam folder. This is because we have a
domainname veerle-en-koen.be, but only use like 4 emailaddress of this
domainname and we get lots of spam to the other emailaddresses of this
domain like , , ...
The reason is that the company where we registered our domainname
forwards all the mail of the domain. So I would like to check the
receiver(s) of the incoming mails to see if one of our 4 really used
emailaddresses are in it, and if not: move the mail to the spam folder.

But I don't think this is possible with the rules of outlook. So now
the real question: I could write something in VBA that does this check,
but how can I make sure this VBA script is automaticcaly executed each
time new email arrives? If I could get an extra button on one of the
outlook toolbars that executes the script when pressed and parses all
the emails in the inbox would be fine as well, is that possible?

Veerle


--
Reiner
--

"Wer fragt, ist ein Narr für fünf Minuten. Wer nicht fragt, bleibt ein Narr
für immer." Chinesische Weisheit
"Erfolg hat, wer ihm entgegengeht, statt ihm nachzulaufen." Onassis,
Aristoteles


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check emails whilst out of the office? abbyT Outlook - General Queries 2 January 23rd 07 01:40 PM
OE will not retrieve incoming emails Widener U Outlook Express 4 September 12th 06 12:35 PM
Not receiving any incoming emails Godz Lady Outlook - General Queries 3 September 12th 06 01:35 AM
Graphics in incoming emails are suppressed Big Al-Bob Outlook Express 2 July 15th 06 10:35 PM
how to disable security check for incoming signed mails Cagdas Ozgenc Outlook - General Queries 0 April 20th 06 07:06 AM


All times are GMT +1. The time now is 10:49 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.