0 votes
by (360 points)

How can I fetch mail attachments from the mail-service to a Silverlight client?
For now I'm trying it with the following code:

 _pop3 = new Pop3();  
    var messages = _pop3.GetMessageList();  
    var message = messages.Find(uniqueId);  
    if (message != null)
       var sequenceNumber = message.SequenceNumber;  
       var msg = _pop3.GetMailMessage(sequenceNumber);  
       foreach (var attachment in msg.Attachments.Where(attachment => 

I know I have to do something with the attachment.Save(), but I have no idea how to send it to the client and, if necessary, decode it and save it to the client's computer.

Applies to: Rebex Secure Mail

1 Answer

+1 vote
by (147k points)
Best answer

Since you can't use POP3 directly from a Silverlight client application, you would have to create a webservice offering methods that correspond to actions you would like to perform from the client, such as "Get list of messages", "Get information about a particular message (including attachment list)" or "Get data of an individual attachment of a particular message". The last of these methods could take a message uniqueID and attachment index as arguments, perform Connect/Login/GetMailMessage and then return an array of bytes that contains the attachment. To convert an instance of Attachment object to an array of bytes, the following code can be used:

MemoryStream temporaryStream = new MemoryStream();
byte[] attachmentData = temporaryStream.ToArray();

(In contrast to Attachment.Save, this doesn't save any data to your filesystem.)