0
votes

I want to save content of the mail to text file so it can be later used in our notification system. To do that I've created an Outlook rule that all mails with certain text in the subject line will be processed by script. The script is simple:

 Public Sub SaveMailAsFile(itm As Outlook.MailItem)
 Dim oMail As MailItem
 Set oMail = Application.ActiveExplorer.Selection.item(1)
 oMail.SaveAs "UNC\PATH\TO\FILE"
 End Sub

eventually I can replace oMail.SaveAs (to avoid the "FROM... TO..." header) with

dim f as FileSystemObject
dim t as TextStream
...
set t= f.OpenTextFile("UNC\PATH\...",ForWriting,True)
t.Write(oMail.Body)
t.close 

but the problem I have now is more annoying - this rule works on SELECTED message, which generally means that the saved text will belong to previous message rather than to the new one.

Is there a way to save text from the message that triggered this script rather than from random one that was currently focused?

1

1 Answers

1
votes

Do not change to a selection. Process itm.

Public Sub SaveMailAsFile(itm As Outlook.MailItem)
 itm.SaveAs "UNC\PATH\TO\FILE"
End Sub