Solved

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

Posted on 2002-03-05
17
242 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
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
 
LVL 49

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 49

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 49

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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

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 49

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

867 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

19 Experts available now in Live!

Get 1:1 Help Now