×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Copying Emails into a VFP table from Outlook

Copying Emails into a VFP table from Outlook

Copying Emails into a VFP table from Outlook

(OP)
Is there some simple way to copy Emails from Outlook (Multiple accounts)? I need to parse the Email content and be able to delete Emails via VFP...

Dennis Kean

Simplicity is the extreme degree of sophistication.
Leonardo da Vinci

RE: Copying Emails into a VFP table from Outlook

Very much off the top of my head, and not tested, but it should give you a start.

CODE -->

oOut = CreateObject("outlook.application")
oNameSpace = oOut.GetNameSpace("MAPI")
oInBox = oNameSpace.GetDefaultFolder(6)

WITH oInBox

  FOR EACH loM IN .Items
    * Display each email; obviously you will want to 
    * store these items somewhere rather than just
    * showing them on the screen	
    ? loM.SenderName
    ? loM.Subject
    ? loM.Body
		
  ENDFOR
	
ENDWITH 

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Copying Emails into a VFP table from Outlook

(OP)
Thanks Mike,

Just what the doctor ordered! happy shades


Dennis Kean

Simplicity is the extreme degree of sophistication.
Leonardo da Vinci

RE: Copying Emails into a VFP table from Outlook

(OP)
Mike,

It works great but not with oNameSpace.GetDefaultFolder(6) I used 5 and it works great! Exactly what I wanted!

Many thanks

Dennis Kean

Simplicity is the extreme degree of sophistication.
Leonardo da Vinci

RE: Copying Emails into a VFP table from Outlook

A value of 5 indicates the Sent mail folder, whereas 6 is the Inbox. So what you will be seeing is the items already sent.

Does that sound right to you?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Copying Emails into a VFP table from Outlook

(OP)
Mike!

No, you are right. I want the InBox. I think that I stumbled into the wrong account, where the inbox is empty or something.

The more important question is how to select the right Email account. I have at least 20 of them.

I found this code to deal with folders, but it does not work... It must be for some previous version of WinOffice. Mine is Win Office 2010...

CODE --> VFP

loApp = CREATEOBJECT("outlook.application")
loSpace = loApp.GetNameSpace("MAPI")
loFolders = loSpace.Folders
loItems = loSpace.Folders.Items  &&  It fails here


FOR lni = 1 TO loSpace.Folders.Count
   lcName = loSpace.Folders(lni).Name
   ? lcName
ENDFOR

*Folders are hierarchical so each folder can contain their own set of folders as well.

FOR lni = 1 TO loSpace.Folders.Count
   loFolders = loSpace.Folders(lni).Folders
   FOR lnSub = 1 TO loFolders.Count
      lcName = loFolders.Folders(lni).Name
      ? lcName
   ENDFOR
ENDFOR 

Dennis Kean

Simplicity is the extreme degree of sophistication.
Leonardo da Vinci

RE: Copying Emails into a VFP table from Outlook

Take a look ar olindex.zip from http://www.foxpert.com/downloads.html

In regard of OLE object collectiona, always use FOR EACH to iterate them:

CODE

loApp = CREATEOBJECT("outlook.application")
loSpace = loApp.GetNameSpace("MAPI")
FOR EACH loFolder IN loSpace.Folders
   ? loFolder.Name
   FOR EACH loSubFolder IN loFolder.Folders
       ? CHR(9)+loSubFolder.Name
   ENDFOR
ENDFOR 

Bye, Olaf.

RE: Copying Emails into a VFP table from Outlook

(OP)
Olaf

Good Example. Thanks...

Concerning OLIndex.zip I downloaded it, but it requires the OLindex DataBase. And it is not included in the zip file. I tried to find info on it on the web and I get no hits in Google... Do you have any ideas where I can get the DBC files?



Never mind it creates its own DB. Very strange, but educational...

Dennis Kean

Simplicity is the extreme degree of sophistication.
Leonardo da Vinci

RE: Copying Emails into a VFP table from Outlook

You can bet Christof will never put anything incomplete as a download.
I remember I had trouble getting it to run, but it will give you anything you need to extract emails and you only need to take parts of its code for that matter.

By the way, I think today Outlook itself got better in finding mails via its own search mechanisms, so this download isn't necessary for that matter, it's still very good to learn about Outlook folder management.

Bye, Olaf.

RE: Copying Emails into a VFP table from Outlook

(OP)
Olaf

I am trying to parse through my Emails to delete all the incoming junk on continuous basis. I get nearly a thousand junk emails every day. And nothing can beat VFP when you want to be specific, inspecting originating IPs, the message body, subject, CC, BB, etc... OLE automation also allows me to cast the Message body into the browser by choosing the HTML body. I have had this idea for a while.

Anyway, thanks for the suggestion.

Dennis Kean

Simplicity is the extreme degree of sophistication.
Leonardo da Vinci

RE: Copying Emails into a VFP table from Outlook

I think you misunderstood.

OLINDEX.zip is a tool creating a word/fulltext index of mails and in that function it has become irrelevant, but you want to do different things accessing the inbox items and for that matter the part of the code iterating the inbox items of course is helpful.

Bye, Olaf.

RE: Copying Emails into a VFP table from Outlook

Dennis,

I'm a bit confused as to whether you are iterating your Inbox or your Sent Items. However, if the former, it occurs to me that you need to do a bit more work.

Certain mail items that appear in the Inbox are not really emails, and don't have certain properties. These include bounce messages and read receipts, and possibly some others. If you try to retrieve some of their properties, you will get an error.

So, inside your FOR EACH loop, you should test for TYPE(.SenderName) = "U". If that is .T., then the mail item is one of those exceptional types, so you should refrain from accessing any of its properties.

I know this doesn't directly answer any of your questions, but I recall that it caught me out once, so I thought I had better mention it.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Copying Emails into a VFP table from Outlook

(OP)
Mike

Thank you Mike. Your comments are always helpful. There are several ways to pluck the Emails. I used this one.

CODE --> VFP

FOR EACH loSubFolder IN loFolder.Folders
		
		IF loSubFolder.Name = "Inbox"
			FOR EACH Email IN loSubFolder.Items
				APPEND BLANK 
				REPLACE body 		WITH Email.body
				REPLACE made_time 	WITH Email.CreationTime
				TRY
					REPLACE gotbyname 	WITH Email.ReceivedByName
				CATCH 
				ENDTRY 
				REPLACE got_time 	WITH Email.ReceivedTime
				TRY 
					REPLACE got_name 	WITH Email.Recipients.Item.name
				CATCH 
				ENDTRY 

				REPLACE senderadd 	WITH Email.SenderEmailAddress
				REPLACE sendrname 	WITH Email.SenderName
				REPLACE sent_on 	WITH Email.SentOn
				REPLACE Esize 		WITH Email.Size
				REPLACE subject 	WITH Email.Subject
				TRY 
					REPLACE Send_to		WITH Email.To
				CATCH 
				ENDTRY 
				TRY 
					REPLACE html 		WITH Email.HTMLBody
				CATCH 
				ENDTRY 

				Validate_Email()
			ENDFOR 
		ELSE 
		ENDIF
   ENDFOR 

The application is nearly done. From what I have seen so far, OLE Automation is not the fastest Ferrari. It is more like a tricycle. It is going at about 5-10 Emails per second. And it is not my code, which take no more than 0.01 seconds. Outlook seems to do lots of management as you iterate through the Emails. Frequently it pauses for a moment and continues. I don't think there is a cure for that. So I am thrilled to be able to do this... no matter what the speed.

My next obstacle is creating custom folders and moving mail into them. I have not found code which works. Some code I which I did find and test uses OLE variables which simply do not come up when I insert them in the functions of the examples given. But let me save that for another question, if I fail to get ahead.

You guys have been very helpful. Thank you all for that....

Dennis Kean

Simplicity is the extreme degree of sophistication.
Leonardo da Vinci

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close