Mail.Attachments Property


Gets an array of the attachments of the email message.
This property is obsoleted by Mail.AttachmentList

[Visual Basic 6.0]
Public Property Get Attachments() As Variant
[Visual C++]
public: get_Attachments(VARIANT* pVal);

Property Value

A Attachment array instance of of the attachments of the email message.

Example

[Visual Basic 6.0, VBScript, Visual C++] To get the full samples of EAGetMail, please refer to Samples section.

[Visual Basic 6.0]
Private Sub ParseAttachment()
On Error GoTo ErrorHandle
    Dim oMail As New EAGetMailObjLib.Mail
    Dim oTools As New EAGetMailObjLib.Tools
    
    oMail.LicenseCode = "TryIt"
    oMail.LoadFile "c:\test.eml", False
    Dim tempFolder As String
    tempFolder = "c:\temp"
    
    ' Decode winmail.dat (TNEF) automatically'
    oMail.DecodeTNEF

    Dim i, Count
    Dim atts
    atts = oMail.Attachments
    i = LBound(atts)
    Count = UBound(atts)
    If (Count >= i) Then
        If Not oTools.ExistFile(tempFolder) Then
            oTools.CreateFolder (tempFolder)
        End If
        
        For i = LBound(atts) To Count
            Dim att As Attachment
            Set att = atts(i)
            Dim attname
            attname = tempFolder & "\" & att.Name
            att.SaveAs attname, True
        Next
    End If
    Exit Sub
ErrorHandle:
    MsgBox Err.Description
 
End Sub
 

[VBScript] Sub ParseAttachment() Dim oMail Set oMail = CreateObject("EAGetMailObj.Mail") Dim oTools Set oTools = CreateObject("EAGetMailObj.Tools") oMail.LicenseCode = "TryIt" oMail.LoadFile "c:\test.eml", False Dim tempFolder tempFolder = "c:\temp" ' Decode winmail.dat (TNEF) automatically oMail.DecodeTNEF Dim i, Count Dim atts atts = oMail.Attachments i = LBound(atts) Count = UBound(atts) If (Count >= i) Then If Not oTools.ExistFile(tempFolder) Then oTools.CreateFolder (tempFolder) End If For i = LBound(atts) To Count Dim att Set att = atts(i) Dim attname attname = tempFolder & "\" & att.Name att.SaveAs attname, True Next End If End Sub
[Visual C++] //if you do not use MFC, please add this line to support CString type. #include <atlstr.h> #include "eagetmailobj.tlh" using namespace EAGetMailObjLib; void ParseAttachment() { IMailPtr oMail = NULL; CString tempFolder = _T("c:\\temp"); try { oMail.CreateInstance(__uuidof(EAGetMailObjLib::Mail)); oMail->LicenseCode = _T("TryIt"); oMail->LoadFile(_T("c:\\test.eml"), VARIANT_FALSE); // Decode winmail.dat (TNEF) automatically oMail->DecodeTNEF(); LONG UBound = 0, LBound = 0; _variant_t atts = oMail->Attachments; SAFEARRAY *psa = atts.parray; SafeArrayGetLBound(psa, 1, &LBound); SafeArrayGetUBound(psa, 1, &UBound); INT count = UBound-LBound+1; ::CreateDirectory(tempFolder.GetString(), NULL); for(long i = LBound; i <= UBound; i++) { _variant_t vtAtt; SafeArrayGetElement(psa, &i, &vtAtt); IAttachmentPtr pAtt; vtAtt.pdispVal->QueryInterface(__uuidof(IAttachment), (void**)&pAtt); CString name = (TCHAR*)pAtt->Name; CString attname = tempFolder; attname.Append(_T("\\")); attname.Append((TCHAR*)pAtt->Name); pAtt->SaveAs(attname.GetString(), VARIANT_TRUE); } } catch(_com_error &ep) { MessageBox(NULL, (TCHAR*)ep.Description(), _T("Error"), MB_OK); } }

See Also

Mail.AttachmentList Property
Attachment Class

Online Tutorials

Parse Email in VB6 - Tutorial
Parse winmail.dat(TNEF) in VB6 - Tutorial
Parse Email in Delphi - Tutorial
Parse winmail.dat(TNEF) in Delphi - Tutorial
Parse Email in VC++ - Tutorial
Parse winmail.dat(TNEF) in VC++ - Tutorial