When an Outlook user composes and sends a message using either Rich Text Format or HTML Format, Outlook automagically generates a file, winmail.dat, and attaches it to the end of the email. The winmail.dat contains the rich text body and original attachments. EAGetMail provides the TNEF parser to decode the winmail.dat. With this feature, you application has the highly compatibility with the outlook email.
Example
[Visual Basic] The following example demonstrates how to deal with the winmail.dat attachment.
[Visual Basic]
Sub ParseAttachments( emailFile As String )
Dim oMsg As ANPOPLib.POPMSG
Dim oTMsg As ANPOPLib.POPMSG
Dim i, nRet, nCount, nSize, x, y 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
If LCase(fileName) = "winmail.dat" Then
'this is a OUTLOOK RTF attachment, decode it.
Set oTMsg = oMsg.DecodeTNEF( oMsg.GetAttachmentChunk(i), 1 )
y = oTMsg.GetAttachmentCount()
For x = 1 To y
If oTMsg.SaveAttachment( tempFolder, x ) <> 0 Then
err = "error with SaveAttachment"
GoTo ErrorHandler
End If
Next
Else
nSize = oMsg.GetAttachmentSize(i) 'get attachment size
If oMsg.SaveAttachment( tempFolder, i ) <> 0 Then 'save attachment to temporary directory
err = "error with SaveAttachment"
GoTo ErrorHandler
End If
End If
Next
ErrorHandler:
Set oMsg = Nothing
End Sub
2001-2007 © Copyright AdminSystem Software Limited. All rights reserved.