SaveAttachment Method

Save attachment file.

[Syntax]
C++: HRESULT SaveAttachment( BSTR sPath, int nCount, long* pVal )
Visual Basic: SaveAttachment( sPath As String, nCount As Integer ) As long
C#: long SaveAttachment( string sPath, int nCount )

Parameters

sPath

Target directory the attachment is saved.

nCount

Ordinal number of file attachment. The minimum value is 1, the maximum value is returned by method GetAttachmentCount.

Return value

If this method succeeds, the return value is zero. If it fails, the return value is non-zero.

Remarks

If the target directory does not exist, this method fails.

Usage Example

[Visual Basic]
Sub ParseAttachments( emailFile As String )
  Dim oMsg As ANPOPLib.POPMSG
  Dim i, nRet, nCount, nSize As Integer
  Dim tempFolder, fileName, err As String
  
  Set oMsg = new ANPOPLib.POPMSG
  nRet = oMsg.ImportFile( emailFile )
  If nRet <> 0 Then
    err = "error with ImportFile"
    GoTo ErrorHandler
  End If
  
  tempFolder = "c:\temp_attachments"
  If oMsg.CreateFolder( tempFolder ) <> 0 Then
    err = "error with Create temporary folder"
    GoTo ErrorHandler
  End If
  
  nCount = oMsg.GetAttachmentCount() 'get total count of attachments
  For i = 1 To nCount
    fileName = oMsg.GetAttachmentName(i) 'get attachment name
    nSize = oMsg.GetAttachmentSize(i) 'get attachment size
    'save attachment to temporary directory
    If oMsg.SaveAttachment( tempFolder, i ) <> 0 Then 
      err = "error with SaveAttachment"
      GoTo ErrorHandler
    End If
  Next
  
ErrorHandler:
  Set oMsg = Nothing
End Sub

See Also

SaveAttachmentAs Method
GetAttachmentCount Method
GetAttachmentChunk Method
GetAttachmentSize Method
GetAttachmentName Method


2001-2007 © Copyright AdminSystem Software Limited. All rights reserved.