Reading Email Attachment Contents Directly From Memory

Question:

I've just discovered the SaveAttachedFile method. Is this the recommended method of doing this? I'd prefer to not have to save the attachment to another location before I process it. It would be nicer to be able to simply read the file from either memory or the temporary store allocated by Exchange.

Answer:

With Chilkat Mail there is no need to save the attachment to a file -- you can access the attachment's content directly from memory. (You can, however, save the attachment to a file using SaveAttachedFile method.) To do this, call GetAttachmentString, GetAttachmentStringCRLF, or GetAttachmentData. The first argument to each of these methods is an index specifying the index of the attachment to be retrieved (0 being the first). The GetAttachmentString methods return a Unicode string. If your text attachment is in another character encoding, such as iso-8859-1, utf-8, shift_JIS, etc. you can specify this in the 2nd argument and Chilkat will convert the attachment data from that charset to Unicode, so your VB6 / VB.NET / C# / ASP / etc. program can use the string. The GetAttachmentData method returns the attachment as a byte array.