Results 1 to 7 of 7

Thread: [RESOLVED] Parsing SenderEmailAddress on incoming Items in Outlook 2003

  1. #1

    Thread Starter
    New Member lordharlock's Avatar
    Join Date
    May 2006
    Posts
    8

    Resolved [RESOLVED] Parsing SenderEmailAddress on incoming Items in Outlook 2003

    I am trying to create some VBcode in Outlook 2003 that will inspect the SenderEmailAddress and route the email to the appropriate sub folder. As an example to this problem if an incoming email came from the SenderEmailAddress [email protected] I want to move all email from the domain of "@yahoo.com" to the sub folder of my inbox named Yahoo Mail. In trying to do this I ran into a problem where I am getting an error 424 object required. Is there another way to accomplish what I am looking to do? Any help would be greatly appreciated, here is what I have so far:

    VB Code:
    1. Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
    2.     Dim objNS As NameSpace
    3.     Dim objInbox As MAPIFolder
    4.     Dim objMoveFolder As MAPIFolder
    5.     Dim intDomainNameStart As Integer
    6.     Dim strUserName As String
    7.     Dim strDomainName As String
    8.    
    9.     Set objNS = Application.GetNamespace("MAPI")
    10.     Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
    11.    
    12.     '--Sort by SenderEmailAddress--
    13.     intDomainNameStart = Item.SenderEmailAddress.IndexOf("@") 'I get the 424 Error Here
    14.     strUserName = Item.SenderEmailAddress.Substring(0, intDomainNameStart - 1)
    15.     strDomainName = Item.SenderEmailAddress.Substring(intDomainNameStart)
    16.    
    17.     Select Case strDomainName
    18.         Case "@yahoo.com"
    19.             Set objMoveFolder = objInbox.Folders("Yahoo Mail")
    20.         'Case ""
    21.             'Set objMoveFolder = objInbox.Folders("").Folders("")
    22.         Case Else
    23.             '
    24.     End Select
    25.    
    26.     If Not objMoveFolder Is Nothing Then
    27.         Item.Move objMoveFolder
    28.     End If
    29.  
    30.     Set objMoveFolder = Nothing
    31.     Set objInbox = Nothing
    32.     Set objNS = Nothing
    33. End Sub

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Parsing SenderEmailAddress on incoming Items in Outlook 2003

    Welcome to the forums!

    You could try using the InStr function to find the position of the "@".

    VB Code:
    1. intDomainNameStart = InStr(1, Item.SenderEmailAddress, "@")
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  3. #3
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Parsing SenderEmailAddress on incoming Items in Outlook 2003

    You do know that you could use a "rule" to achieve this same result without any code?
    Its on the Tools menu under "Rules and Alerts...".
    Attached Images Attached Images  
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  4. #4

    Thread Starter
    New Member lordharlock's Avatar
    Join Date
    May 2006
    Posts
    8

    Re: Parsing SenderEmailAddress on incoming Items in Outlook 2003

    I do know that but I have many more rules than just the one in the example that exceed the 32k limit on rules allowed. So I am trying to get around that by simulating the rules wizard through VBCode.

    BTW the InStr function worked on that first line and now I am getting the same error for the subsequent two lines.

  5. #5
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Parsing SenderEmailAddress on incoming Items in Outlook 2003

    OK, so code is the way to go.
    You are getting errors on the next two lines because of Substring, which is not a vba Function
    I would suggest using the vba function "Mid" to get the domain and "Left" to get the UserName.
    VB Code:
    1. strUserName = Left(Item.SenderEmailAddres, intDomainNameStart - 1)
    2.     strDomainName = Mid(Item.SenderEmailAddress, intDomainNameStart)
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  6. #6

    Thread Starter
    New Member lordharlock's Avatar
    Join Date
    May 2006
    Posts
    8

    Re: Parsing SenderEmailAddress on incoming Items in Outlook 2003

    DKenny,

    That last bit of code did not fix the problem it gave me this error "outlook run-time error 438" Object does not support that method. The code may not have worked but it set me on the right path to fix the code. I change the code so that the parsing looks like this:

    VB Code:
    1. '--Sort by SenderEmailAddress--
    2.     strSenderEmailAddress = Item.SenderEmailAddress
    3.     intSenderEmailAddressLen = Len(strSenderEmailAddress)
    4.     intDomainNameStart = InStr(1, strSenderEmailAddress, "@")
    5.     strUserName = Left(strSenderEmailAddress, intDomainNameStart - 1)
    6.     strDomainName = Mid(strSenderEmailAddress, intDomainNameStart)

    I would like to thank you for your help with this problem!!

  7. #7
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Parsing SenderEmailAddress on incoming Items in Outlook 2003

    Not a probnlem, just glad you were able to sort it now. Please don't forget to mark this thread as resolved (its under Thead tools at the top of the page).
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width