Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Segregating mails

Posted on 2004-08-10
5
Medium Priority
?
460 Views
Last Modified: 2010-04-08
Hello Experts,
   I want to segregate mails that have the same date value in mail recieved date and mail sent date With the mails that have different values for these fields into different folders. Can you guide me as to how an I achieve this?
Rgds
Ovais
0
Comment
Question by:MOvais_Khan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 15

Expert Comment

by:will_scarlet7
ID: 11771197
I think the only way to do this would be to write a MACRO that scan through your folder and compares each items DateValue(ReceivedTime) with the DateValue(SentOn) and if they match then moves them to a different folder.
0
 

Author Comment

by:MOvais_Khan
ID: 11772014
But how to write the macro, I dont have any experience in VB or VBA. Any reference material that I can study and implement this method. Also What will be the method (function) to move the mails to the seperate folder
0
 
LVL 15

Expert Comment

by:will_scarlet7
ID: 11772055
Something like this might work:

Sub MoveMail()
   
    'Declare Objects & Variables
    Dim oOutlook As Outlook.Application
    Dim oNs As Outlook.NameSpace
    Dim oFromFldr As Outlook.MAPIFolder
    Dim oToFldr As Outlook.MAPIFolder
    Dim oMessage As Object
    Dim oMBox As String
   
    'Setup the object variables
    Set oOutlook = New Outlook.Application
    Set oNs = oOutlook.GetNamespace("MAPI")
    oMBox = MsgBox("First select the folder FROM which to get your mail:", vbOKOnly)
    Set oFromFldr = oNs.PickFolder
    oMBox = MsgBox("Now select the folder to move the messages to:", vbOKOnly)
    Set oToFldr = oNs.PickFolder

    'Move all mailitems from origin to destination folders if Rec'd Date and Sent Date are the same
    For Each oMessage In oFromFldr.Items
        If DateValue(oMessage.ReceivedTime) = DateValue(oMessage.SentOn) Then
            oMessage.Move oToFldr
        End If
    Next oMessage
   
    'Clean up object variables
    Set oOutlook = Nothing
    Set oNs = Nothing
    Set oFromFldr = Nothing
    Set oToFldr = Nothing
   
End Sub
0
 

Author Comment

by:MOvais_Khan
ID: 11772522
gives me debug error on the line
     If DateValue(oMessage.ReceivedTime) = DateValue(oMessage.SentOn) Then

Just Curious, Is this VBA, Can i have some study and reference material for VBA, as i have a lot of customizations that i think i can achieve with programming, so its better I learn about it
0
 
LVL 15

Accepted Solution

by:
will_scarlet7 earned 1000 total points
ID: 11845056
Oops, I just realised I never got back to you on this. Sorry. Try assigning the dates to variables and then comparing them in the if statement like this:
****************************
Sub MoveMail()
   
    'Declare Objects & Variables
    Dim oOutlook As Outlook.Application
    Dim oNs As Outlook.NameSpace
    Dim oFromFldr As Outlook.MAPIFolder
    Dim oToFldr As Outlook.MAPIFolder
    Dim oMessage As Object
    Dim oMBox As String
    Dim inDate As Date, outDate As Date
   
    'Setup the object variables
    Set oOutlook = New Outlook.Application
    Set oNs = oOutlook.GetNamespace("MAPI")
    oMBox = MsgBox("First select the folder FROM which to get your mail:", vbOKOnly)
    Set oFromFldr = oNs.PickFolder
    oMBox = MsgBox("Now select the folder to move the messages to:", vbOKOnly)
    Set oToFldr = oNs.PickFolder

    'Move all mailitems from origin to destination folders if Rec'd Date and Sent Date are the same
    For Each oMessage In oFromFldr.Items
        inDate = DateValue(oMessage.ReceivedTime)
        outDate = DateValue(oMessage.SentOn)
        If inDate = outDate Then
            oMessage.Move oToFldr
        End If
    Next oMessage
   
    'Clean up object variables
    Set oOutlook = Nothing
    Set oNs = Nothing
    Set oFromFldr = Nothing
    Set oToFldr = Nothing
   
End Sub
****************************

And yes this is VBA. I don't really know what to reccomend as far as study material. There are books available, but I personnaly have a hard time learning from books and prefer to learn by studying other peoples examples. There is a cool website that you might find useful:

http://www.outlookcode.com/code2.aspx?level=b


This book looks good:

http://www.pearsoned.co.uk/bookshop/detail.asp?item=100000000055448&affid=tre
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many people use more than one email account and so it becomes difficult for them to manage them when they use separate accounts,  so, in this article, I have shared an easy way to add Other Mail Accounts in your Google Inbox. It helps to combine all…
This article will help to fix the below error for MS Exchange server 2010 I. Out Of office not working II. Certificate error "name on the security certificate is invalid or does not match the name of the site" III. Make Internal URLs and External…
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question