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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VFP and Outlook Automation

Status
Not open for further replies.

stuartmckay

Programmer
Dec 4, 2006
13
CA
I need some guidance on how to save an email to file after a user click the send button in Outlook.
Steps are:
1) From VFP generate a new email.
2) User fills out email, then hits send.
3) I now want to save the email in .msg format.

The application is written in VFP 5.0. The problem I seem to have is that the email does not appear to have a id assigned when it is created so I am unsure of how to figure out the last sent email... I guess the email may even be in the outbox depending on the users configuration.

Any help would be greatly apprecaited.

Stuart
 
Took a look at the Faq's before posting, unfortunatley did not find what I was looking for.
The problem is being able to figure out that the user has clicked the send button, then tracking down the email they just sent.
 
Stuart,

How about something like this:

Loop through the items in the SentMail folder. For each item, pick up the value of the SentOn property. The item with the latest SentOn will be the one that was just sent (well, maybe). You can then call its SaveAs method to save it.

Code:
oOut = CreateObject("outlook.application")
oNameSpace = oOut.GetNameSpace("MAPI")
oDrafts = oNameSpace.GetDefaultFolder(5)

FOR EACH loItem IN oDrafts.Items
  * check SentOn on take appropriate action  
ENDFOR

This is completely off the top of my head, and not tested, but it might be worth trying.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
In VFP 7 and later, you can hook your code to events generated by Outlook. Is there any reason you're in VFP 5, which is nearly 10 years old?

Tamar
 
Mike -"Off the Top of Your Head" - is pretty good!
In a thread on Exporting all emails to acess database the item.senton is the key to identifying the information that is saved out.
The expamle gets all the messages, so one might convert the code, store in a dbf, and test the latest records to see if they need to be stored or not.
The code to get the data into the dbf might look something like:

For Each item In items
*add a record to database

datesent=item.Senton
subject =item.Subject
body=item.Body
Next

A link to the discussion-
By the way, If it is in any way inapproporate to refer to other sights and other language examples, someone please advise. I generally learn by reading here, and also by looking everywhere else google can see for examples.
wjwjr
 

Hi Wjwrjr,

If it is in any way inapproporate to refer to other sights and other language examples, someone please advise.

My understanding is that there is no objection if the site is genuinely useful and helps answer the question.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
A slight variation on Mike Lewis's idea with a tickler from your initial post:

You could place your own self-generated ID or special string in the subject or body of the message. Then when looping through the messages in the Sent folder, you can identify the exact message by comparing against the specific string you embedded.

Mike Krausnick
Dublin, California
 
What I ended up doing was to write a unique id into the mileage field when the email is created. I then find the email that contains the unique id.

ie.
When creating the email
oMailItem.Mileage = 'TEST999'

When searching the sent items
oMailItem = oSentfolder.items.find("[Mileage]='TEST999'")
 
Stuart,

What I ended up doing was to write a unique id into the mileage field when the email is created.

Great idea. That field's always been a mystery to me. It's interesting that you've actually found a use for it.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
I shouldn't take the credit for this. I found the idea to use this field on the site The site is in promotion of a book Microsoft Outlook programming by Sue Mosher. Found it to be a very useful website.

Stuart
 
A thought - what if the user decided to save the sent copy to a folder other than sent items, or decided not to save a copy?

Sorry if I've just thrown a spanner in the works!

Stewart
 
You make a good point. What I have done is have an auto save option. This will only work if mail ( at least in v1.0 of this ) is routed to the sent items folder. Otherwise what I have done is include the option that the customer can click on an email in outlook then flip into our app and press the outlook button which will save the selected email.

Appreciate everyones input!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top