Solved

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

Posted on 2002-03-05
17
243 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 50

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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 50

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 50

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 50

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 50

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Add records to a form to a table 11 41
Calculation in Access 5 26
Access Changing Number to Date with Seperator 5 21
Dirty form - conditional formatting 5 27
In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

778 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