Solved

Downloading and restoring attachments in OpenPop.net

Posted on 2014-02-09
1
1,462 Views
Last Modified: 2014-02-09
I've been using OpenPop.net to retrieve emails from a server. For the time being I skipped the functionality of downloading attachment emails to keep things simple. Now I need to go back and enable this functionality. A couple questions.
#1 Does openpop.net automatically download the attachments as part of the message? Will I need to download the messages separately? I currently use:
foreach (OpenPop.Mime.Message m in newMessages)
{
m.save(file);
}
#2 If I load the message how do I add all the existing attachments of saved email to the new email to be sent out (restored) to the server?
I've got something like this so far:
                        List<MessagePart> attachments = message.FindAllAttachments();
                        foreach (MessagePart attachment in attachments)
                        {
                            SendMessage.Attachments.Add(new Attachment
                            {
                                FileName = attachment.FileName,
                                ContentType = attachment.ContentType.MediaType,
                                Content = attachment.Body
                            });
                        }
But the problem with this is that FileName and Content both have those little red squiggly lines underneath them. I can change FileName to "Name" but I can't figure out what Content would be. Any help would be appreciated.
0
Comment
Question by:drayne
1 Comment
 

Accepted Solution

by:
drayne earned 0 total points
ID: 39846326
Here was the answer:
                        //Get the attachments
                        IEnumerable<MessagePart> attachments = message.FindAllAttachments();
                        foreach (MessagePart attachmentMessagePart in attachments)
                        {
                            MemoryStream stream = new MemoryStream(attachmentMessagePart.Body);
                            Attachment attachment = new Attachment(stream, attachmentMessagePart.ContentType);
                            attachment.Name = attachmentMessagePart.FileName;
                            attachment.ContentId = attachmentMessagePart.ContentId;
                            SendMessage.Attachments.Add(attachment);
                        }
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now