StoreMessage Method

Store the specified message in a file.

Syntax

object.StoreMessage( number, filename )

The StoreMessage method syntax has the following parts:

Part Description
object An object expression that evaluates to an InternetMail object.
number A long integer which specifies the message to store.
filename A string which specifies the name of the file to store the message in.

Return Type

Integer

Remarks

The StoreMessage method retrieves the specified message from the mail server and stores it in a file. The number argument specifies the message to retrieve and the filename argument specifies the name of the file that the message will be stored in.

For applications which need to store messages on the local system, the StoreMessage method is somewhat more efficient than using the GetMessage and ExportMessage methods to load and store the message. StoreMessage does not attempt to analyze the message or change the current message contents.

This method will return a value of zero if the action was successful. Otherwise, a non-zero error code is returned which indicates the cause of the failure.

Example

The following example connects to a mail server and retrieves each of the mail messages, storing them in a file on the local system:

    Dim strFileName As String
    Dim nMessage As Long, nError As Long

    nError = InternetMail1.Connect(strServerName, , strUserName, strPassword)
    
    If nError <> 0 Then
        MsgBox "Unable to connect to " & strServerName & vbCrLf & _
               InternetMail1.LastErrorString, vbExclamation
        Exit Sub
    End If
    
    If InternetMail1.LastMessage = 0 Then
        MsgBox "The mailbox is currently empty", vbInformation
        InternetMail1.Disconnect
        Exit Sub
    End If
    
    For nMessage = 1 To InternetMail1.LastMessage
        strFileName = "c:\temp\msg" & Format(nMessage, "00000") & ".txt"
        nError = InternetMail1.StoreMessage(nMessage, strFileName)
        If nError <> 0 Then
            MsgBox "Unable to store message " & nMessage & vbCrLf & _
                   InternetMail1.LastErrorString, vbExclamation
            Exit For
        End If
    Next
    
    If nError = 0 Then
        MsgBox "Stored " & InternetMail1.LastMessage & " messages", vbInformation
    End If
    
    InternetMail1.Disconnect

See Also

GetMessage Method, ExportMessage Method


Copyright © 2008 Catalyst Development Corporation. All rights reserved.