Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2002-03-05
17
Medium Priority
?
249 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 54

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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 54

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 54

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 54

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 54

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

824 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