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

Scrip or Rule to save automatically an email to a file

Status
Not open for further replies.

vicentell

Technical User
Sep 18, 2003
84
MX
I am trying to create a scrip or a rule on microsoft outlook that check for incoming email and save it as a txt file in automatic way.
I tried creating a rule but it does not have the option to save it a file, i was wondering if there is scrip or another way to do that.
thanks in advance
 
vicentell,
take a look at saveas which is part of .class which is part of .selection. not sure is you can do automatically. i have doe it with .selection before. remember you have to check for invalid charaters in the email subject.
hth
regards,
longhair
 
This is my scenario.

I have an application that monitors my Computer Room, Everytime an alert is trigger this monitor send me and email, now I am trying to take this specific email and save it as a text file in order to manipulate this file for a pager alert.

I found that you can create a macro using .saveas method

The macro is working just I dont know yet how to activate it as a rule or something like that. In the new rule properties there you can choice either run a script or perform a custom action, but I dont find how to do it. the macro works only in a manual mode I am tring to find something in automatic mode.

thanks in advance
 
Hello

I would like to do the same thing that vincentell posted.

I have a rule in Outlook 2002 that automatically copies the message to a folder.

The part I want is -

-select all of the messages in the folder
-save to a .txt file to a specific network directory
-remove the e-mails once they are saved to a .txt.

Can it be done? If so, then how?

Thanks in advance
Dave



 
ddeegan,
yes it can be done. did you take a look at my suggestions to vincentell?
these apply to vba.
have you got anything beyond the pseudo code that you have posted?
regards,
longhair
 
longhair,

I feel dumb, but I don't know what you mean by "take a look at saveas which is part of .class which is part of .selection. "

Do you mean "File | Save As" or are you accessing code somewhere?

I am not unsderstanding - how do you get there?
 
Hi there
This is what I done:
on your outlook go to Tools-Macros-Visual Basic editor
create a new project.

Here the lines
------------------------------------------------------
Sub Create_log(MyMsg As MailItem)

MyMsg.SaveAs "C:\here\IMS_Alarm.txt", olTXT

End Sub

------------------------------------------------------

after that you can create a rule, for any message that arrives and save it to a file or whatever.

Try it, I tried to have it automatically, but everytime the rule runs it ask to accept and you have to manually acept it, I am still trying to find anything to avoid that and runs in auto way. i did not find anything yet.



 
ddeegan,
what you will need to do is create a macro that will do this work for you. i'm in the moddle of something now, but poke around in help and search the forums. see if you can come up with some ideas and post back. i'll try to post some code later.
regards,
longhair
 
ddeegan,
untested:
Code:
Sub MySaveAs()
    Dim objApp As Outlook.Application
    Dim objSel As Outlook.Selection
    Dim x As Integer
    Dim sSubjectName As String
    Dim ynTried As Boolean
    Dim dteDate As String
    Dim fs
    Dim myPath As String
    Dim Final As String
    
'   Find the currently selected emails
    Set objApp = CreateObject("Outlook.Application")
    Set objSel = objApp.ActiveExplorer.Selection
    dteDate = Format(Date - 3, "MM-DD-YY")
    Set fs = CreateObject("Scripting.FileSystemObject")
    Final = "c:\test\" & dteDate
    MkDir Final

' For each email
    For x = 1 To objSel.Count
        With objSel.Item(x)
        ' perform save only on selected mail messages
            If .Class = olMail Then
            ' some subjects are unsuitable for file names
            ' so allow renaming if necessary
                sSubjectName = .Subject
                ynTried = False
                If InStr(1, sSubjectName, Asc(58), 1) _
		' you will need to add aditional Asc() characters here
		Then GoTo ErrorSaving
                On Error GoTo ErrorSaving
                .SaveAs Final & "\" & sSubjectName & x & ".msg", olMSG
                'On Error GoTo 0
            End If
        End With
    Next
    Set objSel = Nothing
    Set objApp = Nothing
    Exit Sub
    
ErrorSaving:
    If ynTried Then 'they only get one chance to rename the message
        MsgBox "The message '" & sSubjectName & "' was not saved successfully", vbOKOnly, "Save Failed"
        Resume Next 'skips the save
    Else
    ' get a new subject name from user
        ynTried = True
        MsgBox (sSubjectNames & " not a valid name")
        sSubjectName = InputBox("Error:  Subject name not suitable.  Please type a new name excluding any special characters (i.e. :,'.!@ etc)", _
                "Save Failed", sSubjectName)
        Resume
    End If
End Sub
there are still some chores for you to do, such as add the additional ASC for any 'special' characters - work in your delete method. but this should get you started.
hth
regards,
longhair
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top