Zip Component, Email Component, Encryption Component ActiveX Control for Zip Compression .NET Components for ASP.NET
ActiveX and .NET Components for Zip Compression, Encryption, Email, XML, S/MIME, HTML Email, Character Encoding, Digital Certificates, FTP, and more ASP Email ActiveX Component


Index of Chilkat Blog Posts

November 11, 2005

Attachments within embedded emails.

Platform: .NET
Class: Email
Method/Property: GetAttachedMessage
Question: I would like to download individual file attachments from an email that has already been forwarded. For example:

Dim bundle as Chilkat.EmailBundle
bundle = Mailman.CopyMail()
	
Dim email as Chilkat.Email
email = bundle.GetEmail(i)
	
Dim c as integer
For c = 0 to bundle.MessageCount - 1
    If email.NumAttachedMessages > 0 then
        '''how do I get the original email and download the file attachments if any.
    else
        Dim i as integer
        For i = 0 to email.NumAttachments - 1
            email.SaveAttachedFile(j, \"C:\FileAttachments\\")
        next i
    end if
next c

Answer:
You can get the embedded (attached) email as an Email object, and then fetch/save the attachments contained within it. For example:

...
    If email.NumAttachedMessages > 0 then
        Dim numAttached as integer
        numAttached = email.NumAttachedMessages
        Dim j as integer
        for j = 0 to numAttached-1
            Dim aEmail as Chilkat.Email
            aEmail = email.GetAttachedMessage(j)
            Dim i as integer
            For i = 0 to aEmail.NumAttachments - 1
                aEmail.SaveAttachedFile(i, \"C:\FileAttachments\\")
            next i
        next j
    else
        Dim i as integer
        For i = 0 to email.NumAttachments - 1
            email.SaveAttachedFile(i, \"C:\FileAttachments\\")
        next i
    end if
...


Privacy Statement. Copyright 2000-2011 Chilkat Software, Inc. All rights reserved.
Send feedback to support@chilkatsoft.com

Components for Microsoft Windows XP, 2000, 2003 Server, Vista, Windows 7, and Windows 95/98/NT4.