Solved

Check for Mail in outlook every X seconds and if subjuect="value" then unattach..

Posted on 2002-03-05
17
246 Views
Last Modified: 2006-11-17
Hi , im not sure if this can be done but i want to moniotr an Outlok inbox for incoming mails and if a certain subject line contains a value (like you use the rules, exxcept i cant use incoming rules on the inbox as it is a MAPI connection to a Notes Mailbox)

How would i poll the Outlook for new mail then if unattach a document when the subject line is a certain value , then copy document elsewhere...

can this be done - im not sure , but you may know !:-)
0
Comment
Question by:Gaillimh100
[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
  • 8
  • 5
  • 2
  • +2
17 Comments
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 6841132
Hi Gaillimh100,

Sorry, what do you mean by "unattach a document" ?

regards
0
 

Author Comment

by:Gaillimh100
ID: 6843863
I mean , that when the doc comes in , there will be a txt file attahced , i need to "unattach" this and copy to another NT Folder...

Is this ok ..
0
 

Author Comment

by:Gaillimh100
ID: 6853468
hi any takers :-)?
0
Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

 
LVL 52

Expert Comment

by:Ryan Chong
ID: 6855349
Hi Gaillimh100,

This will solve your problem :)

Private Sub Command1_Click()
    Dim iOutlook As Outlook.Application
    Dim myitem As Outlook.MailItem
    Dim myFolder As Outlook.MAPIFolder
    Dim myAttach As Outlook.Attachment
    Set iOutlook = New Outlook.Application
   
    Set myFolder = iOutlook.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)

    List1.Clear
    For i = 1 To myFolder.Items.Count
        Set myitem = myFolder.Items(i)
        If myitem.UnRead = True And myitem.Attachments.Count > 0 Then 'If the Item is UnRead and With Attachment(s)
            List1.AddItem myitem.SenderName & " " & myitem.Subject
            For j = 1 To myitem.Attachments.Count
                Set myAttach = myitem.Attachments(j)
                myAttach.SaveAsFile "D:\" & myAttach.FileName
            Next j
            DoEvents
        End If
    Next i
    Set myitem = Nothing    
    Set myFolder = Nothing
    Set iOutlook = Nothing
End Sub

Cheers,
ryancys
0
 

Author Comment

by:Gaillimh100
ID: 6860587
can this code be modified to check the Subject line for data and if matched then preform the unattach function?

thanks!
0
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 6860642
Hi,

I think you can modify this line:

If myitem.UnRead = True And myitem.Attachments.Count > 0 Then 'If the Item is UnRead and With

to


myCompareValue = "Re"

If InStr(1,myitem.Subject,myCompareValue) > 0 Then '.. Something like this.

It depends on how you want to compare between Subject and the data..

Regards,
ryancys
0
 

Author Comment

by:Gaillimh100
ID: 6860689
for example i need to check for the value

RM130312

in the subject line

where RM is constant and the rest is the date, then i want to unattach the document attahced to that Mail.


Will the above code "poll" outlook or will it have to be triggered by a button or sceduler....?
0
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 6860782
Basically, we can create a User Form, set the Time Interval Property to a certain number, 1000 = 1 minute.

Then add this code in form:

Option Compare Database

Private Sub Form_Load()

End Sub

Private Sub Form_Timer()
    GetAttachment "D:\myFolder", "RM"
End Sub

Private Sub GetAttachment(ByVal CopyTo As String, ByVal CompareValue As String)
    On Error GoTo y
    Dim iOutlook As Outlook.Application
    Dim myitem As Outlook.MailItem
    Dim myFolder As Outlook.MAPIFolder
    Dim myAttach As Outlook.Attachment
    Set iOutlook = New Outlook.Application
   
    Set myFolder = iOutlook.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
   
    List1.Clear
    For i = 1 To myFolder.Items.Count
        Set myitem = myFolder.Items(i)
        If InStr(1, myitem.Subject, CompareValue) > 0 Then
            List1.AddItem myitem.SenderName & " " & myitem.Subject
            For j = 1 To myitem.Attachments.Count
                Set myAttach = myitem.Attachments(j)
                myAttach.SaveAsFile CopyTo & "\" & myAttach.FileName
            Next j
            DoEvents
        End If
    Next i
    Set myitem = Nothing
    Set myFolder = Nothing
    Set iOutlook = Nothing
    Exit Sub
y:
    On Error Resume Next
    Set myitem = Nothing
    Set myFolder = Nothing
    Set iOutlook = Nothing
End Sub

Hope this help
0
 

Author Comment

by:Gaillimh100
ID: 6861157
it tells me " cant find project or library " and it highlights the olFolderInbox word on the line :

Set myFolder = iOutlook.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)

Im not sure why?
0
 

Author Comment

by:Gaillimh100
ID: 6861203
OK ...hmmm seems to have got around that problem above....

Now it runs and asks for the Lotus Notes pw which is ok , then says on List1.clear ....

Run time error 424 Object Required.....

by the code i can see that youve hit the target but its giving me some probs...
0
 
LVL 54

Expert Comment

by:nico5038
ID: 7048481
for Gaillimh100

No comment has been added for the last two months.
So it's time to clean up this TA.
I will leave a recommendation in Community Support that this question is:
 - PAQ'd and pts refunded
Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

Nic;o)
0
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 7050478
To Gaillimh100,

Sorry, i must be busy..

> Now it runs and asks for the Lotus Notes pw which is ok , then says on List1.clear ....

Run time error 424 Object Required.....

The List1 is a ListBox Control, you can find it in your toolbar, or you can simply remove it from the code, test it and see how is the result.
0
 
LVL 2

Expert Comment

by:sgriffin
ID: 7053330
sorry was changing jobs but im back.......
0
 

Author Comment

by:Gaillimh100
ID: 7053361
Sgriffin is collegue of mine , i also moved jobs and so was unable to answer this.....
0
 
LVL 54

Expert Comment

by:nico5038
ID: 7054134
Glad you're all back again.
BTW I miss in your comments the fact that a mailitem has a unique ID, that can be used to check for "already registered"...

Nic;o)
0
 

Author Comment

by:Gaillimh100
ID: 7054142
yes, i need to try this again .....
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 7065376
Per recommendation, points refunded and question closed by
Netminder
CS Moderator
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

630 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