Saving a copy of an email created with Outlook.MailItem after it has been sent.
Posted on 2006-06-19
I have an access database with a form that has a button that i use to automatically create an email with some standard text for the body.
Sometimes my users would like to be able to edit the body before it is sent, so instead of automatically sending it I just display it and let them send it when they are finished.
I am trying to create a copy of the email to save in an extra folder in outlook. I can make of copy of the email after I initially create it but I don't have any of the extra comments that they would input, so i need to copy it after they send it.
Is there a way to catch the send event from inside my access database so i can make a copy of the mailitem object. (i.e. creating an object with events)
I have also thought about creating a rule in outlook that would save any email from the sent folder if it had my pregenerated heading but I would like to accomplish this through code so any new users can automatically use the program without me needing to remeber to set up outlook with the email rule.
I'm currently trying to save the EntryID of the mailitem so i can use it later to cycle through the sent folder and pull out any emails they sent from my program. I haven't gotten far with this in code but the logic flaw i come accross is decideing when i should run the method that does this.
Any help, suggestions and comments is greatly appreciated. Below is a copy of my code.
Dim appOutlook As Outlook.Application, ns As NameSpace
Dim olFolder As Outlook.MAPIFolder, olSent As MAPIFolder
Dim olMail As Outlook.MailItem, olMailCopy As Outlook.MailItem
Set appOutlook = New Outlook.Application
Set ns = appOutlook.GetNamespace("MAPI")
Set olMail = appOutlook.CreateItem(olMailItem)
Set olFolder = ns.GetDefaultFolder(olFolderInbox).Folders("SaveFolder")
Set olSent = ns.GetDefaultFolder(olFolderSentMail)
.To = rsMgr![User_Email]
.Subject = "# " & Me![Num] & " Standard Heading"
.Body = rsMgr![StandardBodyText]
intMsgID = .EntryID
Set olMailCopy = olMail.Copy ' This is the previous code that saves the copy before they have a chance to edit the body text
For Each olMail In olSent.Items ' This is the code that i was working with to cycle through the sent box but I have to find a way to run it after they send the email
If olMail.EntryID = intMsgID Then
Set olMailCopy = olSent.Items()