Solved

Downloading and restoring attachments in OpenPop.net

Posted on 2014-02-09
1
1,573 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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

Title # Comments Views Activity
MYSQL responding very slow 3 50
SSIS GUID Variable 2 34
parsing question on dynamic concatenation 3 34
Connect Gridview column to Textbox in C# 2 40
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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

749 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