'through account' VBA equivalent 
Author Message
 'through account' VBA equivalent

How can I detect the account an email is recieved 'though'

I am trying to do a VBA version of  this Outlook XP rule:
"Apply this rule after the message arrives through the XXX account and move
it to the YYY folder"

The reason the rule won't work for me is because it is client side and
Exchange Server is involved (see Q291514)  So I decided to make a VBA
version.

I got this far, but am stuck trying to see what account the mail came
through.  And No, the 'to' email header is never accurate enough since
spammer BCC me all the time:

Option Explicit

  Private nsMapi As NameSpace
  Private flInbox As MAPIFolder
  Private itMail As MailItem

Private Sub Application_NewMail()
' -- Check every email in the inbox which are unread.
' -- To be sure that no other email are read I store
' -- the processed emails in a different folder after
' -- processing.
On Error Resume Next

  For Each itMail In flInbox.Items
    If itMail.UnRead And itMail.Class = olMail Then
      select case itMail.ReceivedByName  'does this work?
      case "xx"
          itMail.Move flInbox.Folders.Item("FolderNameXXHere")
      case "yy"
          itMail.Move flInbox.Folders.Item("FolderNameYYHere")
      case "zz"
          itMail.Move flInbox.Folders.Item("FolderNameZZHere")
      End select
  Next

End Sub

Private Sub Application_Quit()
' -- Clear memory after quit
  Set flInbox = Nothing
  Set nsMapi = Nothing
End Sub

Private Sub Application_Startup()
' -- When the application starts up the objects are set.
' -- Default for the Namespace is used MAPI.
  Set nsMapi = Me.GetNamespace("MAPI")
  Set flInbox = nsMapi.GetDefaultFolder(olFolderInbox)
End Sub



Sat, 20 Nov 2004 01:09:07 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. VBA's Equivalent of VBScript's SetLocale

2. VBA's Equivalent of VBScript's SetLocale

3. VBA equivalent to GWBASIC's MKI$ ?

4. VB's equivalent voor VBA function: IsObjectValid

5. VBA equivalent to GWBASIC's MKI$ ?

6. Word Equivalent to 'CountIf'

7. Word equivalent to 'Countif'

8. VB equivalent of COBOL 'redefines'?

9. Shortcut Keys and 'SOUND' Equivalent

10. NEW VBA'er(Excel) looking for other VBA'ers

11. 32 bit api equivalent for 'hmemcpy'

12. equivalent of 'clustered' (SQL) in ORACLE

 

 
Powered by phpBB® Forum Software