Solved

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

Posted on 2002-03-05
17
239 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
  • 8
  • 5
  • 2
  • +2
17 Comments
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
Hi Gaillimh100,

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

regards
0
 

Author Comment

by:Gaillimh100
Comment Utility
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
Comment Utility
hi any takers :-)?
0
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
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
Comment Utility
can this code be modified to check the Subject line for data and if matched then preform the unattach function?

thanks!
0
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
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
Comment Utility
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 49

Expert Comment

by:Ryan Chong
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:Gaillimh100
Comment Utility
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
Comment Utility
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
Comment Utility
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 49

Expert Comment

by:Ryan Chong
Comment Utility
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
Comment Utility
sorry was changing jobs but im back.......
0
 

Author Comment

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

Expert Comment

by:nico5038
Comment Utility
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
Comment Utility
yes, i need to try this again .....
0
 
LVL 5

Accepted Solution

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
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.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now