Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Downloading and restoring attachments in OpenPop.net

Posted on 2014-02-09
1
Medium Priority
?
1,807 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

610 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