Solved

Downloading and restoring attachments in OpenPop.net

Posted on 2014-02-09
1
1,424 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

13 Experts available now in Live!

Get 1:1 Help Now