Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving Emails from inbox to deleted folder one at a time

Status
Not open for further replies.

OrbitMascot

Programmer
Jan 23, 2006
30
US
I am working on a database that automatically extracts emails from Outlook. The database extract the emails one at a time. I then would like the database to automatically move the email (that it extracted into Access). Is there a way to send an email from the inbox of Outlook to the deleted folder, one at a time?
Here is the current code that I am using to move all the emails to the deleted folder


Dim myDestFolder As Outlook.MAPIFolder
Set myDestFolder = molNameSpace.GetDefaultFolder(olFolderDeletedItems)
On Error Resume Next
molMail.Move myDestFolder
On Error GoTo 0

Am I on the right track? Any information would be greatly appreciated. Thanks.

 
Hi,

Yes you are. I use a simple function, bit rough but it works

Code:
Function MoveMail(MyMapiFolder As MAPIFolder) As Boolean
' Mail in present folder is moved to a folder called afgehandeld
Dim iNumEmails, i As Integer
Dim strSearchString, strSearchChar, strChrPos, strBaseMessage As String
Dim MyFolder As Outlook.MAPIFolder
Dim MailItem As Outlook.MailItem
Dim objItems As Outlook.Items
Dim error_mail As String

On Error GoTo Error_Handler
MoveMail = True

loop1:
Set MyFolder = MyMapiFolder
Set objItems = MyFolder.Items

iNumEmails = objItems.Count
   If iNumEmails <> 0 Then
      For i = 1 To iNumEmails
         If TypeName(objItems(i)) = "MailItem" Then
            Set MailItem = objItems(i)
            MailItem.Move CurrentMailBox.Folders("afgehandeld") 'the destination folder
            GoTo loop1 'looping could be more elegant then this...
         End If
      Next i
    End If

Exit_Handler:
    Exit Function
Error_Handler:
    MoveMail = False
    debug.print  Err.Number & " " & Err.Description
    Resume Next
End Function
 
Thank you easyit. It took a little time playing around with the code that I was working with. But I finally got it to work. Thank you so much for your insight. It was very helpful.
 
Hello,

I have several 100 emails, that I need to read into access.
Currently, I've been saving them as a .txt file, and then using access to read in the data I need. Is there a way I can read these directly?
They are saved in Outlook Express in groups of a 100 in several different folders.

Thanks in advance...

AccessGuruCarl
Programmers helping programmers
you can't find a better site.
 
Yes you can. You can use the outlook object. After weekend I can post some more code - or search this forum.
EasyIT
 
easyit,

Yes, please post some code examples A.S.A.P...

From my searches so far, I have not come up with anything that matches or comes close to what I was looking for. Other than this post, I will continue to search...

I was hoping for a response from OrbitMascot, It seems he is doing exactly what I need.

If you know of a way to open the email and then save as a text document, that will work as well. Seeing as I already wrote the code to read the text files, and then user told me they had 1400 more still on the email server. Which when forwarded to me I recieve in attachments as xxx.eml files. If I open these files one at a time, then save as a text file I can extract the data I need into access.

But I this point, I'll re-write code if needed to read the files directly from outlook express.


Thanks in advance....

AccessGuruCarl
Programmers helping programmers
you can't find a better site.
 
Hi,

As said - after the weekend. But I overlooked the fact you are using outlook express - I use outlook. I don't know if that makes a difference.

What I do is extract all email from a specified folder, including the subfolders (recursively). The properties of each mailitem (includes subject, messages, receive date/time etc etc) and store it in a table. You should be able to build a text file from this. Or, even simpler, you can use
Code:
MailItem.SaveAs
to store the mail directly as a text file.
Highlight this code in VBA and hit F1 for starters, you should be able to work it out yourself.

EasyIT


 
Thanks for the reply EasyIt...

Yes the User is using Outlook Express. And the Outlook Object only uses outlook, not express.

I did find a code snippet on google where they are doing exactly what I need, only... it's in Outlook.

I'll see if worth the time to revamp the code for my needs. And run a few test files on another machine.

Thanks again for the quick reply...

AccessGuruCarl
Programmers helping programmers
you can't find a better site.
 
AccessGuruCarl

I just read your posts. I currently use Outlook, not Outlook express, I am not sure how different they are. If you do not find the code that you need. I can give you the code that is used in Outlook, maybe with a little tweeking you could get it to work in Outlook Express.


Orbitmascot
 
I'm hoping to do the same thing using a word document. the user enter information in a word form and I need to extract that data into the table. Any code posted will be useful. Any ideas (other than save a comma delimited) would be useful
Thanks

Ian Mayor (UK)
Program Error
Programming is 1% coding, 50% error checking and 49% sweat as your application bombs out in front of the client.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top