Share via


using C# to download attachment from e-mail

Question

Tuesday, November 15, 2011 4:06 AM

Hi,

i want to download the attachment from email using pop3. Please let me know how can i do that

litu Here

All replies (5)

Tuesday, November 15, 2011 7:07 AM ✅Answered

Instead of reinventing wheel you can use one of the libraries available for free.

Pop3Client.

http://www.codeproject.com/KB/IP/pop3library.aspx

http://stackoverflow.com/questions/808871/how-to-grab-attachment-programmatically-c-from-a-pop3-mail

Thanks,
A.m.a.L Hashim

Dot Net Goodies

Wednesday, November 16, 2011 10:13 AM ✅Answered

Hi litu,

Welcome to the MSDN forum!

There is a similar thread in the forum. Please refer to it:

** Get attachment from my email by c#?
**http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/625285ad-d201-433e-ab8f-5cb760a2c4a6

“Uhm, that's depending on how you retrieve your email, or if you're using a third party POP3 email library, check if it is supporting MIME and attachments. Should be documented by the library though.

In my company, we are using OpenPop.NET and it does support mail attachments.

In addition to writting your own mail checked, why not use client mail checked like Outlook or Live Mail? They support auto download of attachment...”

http://www.dotnetspider.com/resources/42151-Email-parser-Reading-emails-using-C.aspx

http://weblogs.asp.net/satalajmore/archive/2007/12/19/asp-net-read-email.aspx

http://www.codeproject.com/KB/IP/Pop3MimeClient.aspx

http://www.fryan0911.com/2009/05/how-to-read-pop3-email-using-c.html

 

Meanwhile, there are a lot of links for you to check out:

http://www.codeproject.com/KB/IP/despop3client.aspx

http://www.example-code.com/csharp/pop3_saveAttachments.asp

Have a nice day!

This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

Yoyo Jiang[MSFT]
MSDN Community Support | Feedback to us


Tuesday, November 15, 2011 1:36 PM

Hi, I have written to upload attachemt in email, i think it would be helpful to u.

private void AddAttachment()
        {
            try
            {
                MailMessage message = new MailMessage {
                    From = new MailAddress(this.from)
                };
                string[] strArray = this.to.Split(new char[] { ',' });
                for (int i = 0; i < strArray.Length; i++)
                {
                    message.To.Add(new MailAddress(strArray[i]));
                }
                message.Subject = this.txtSubject.Text;
                message.Body = "";
                message.Body = message.Body + "\n" + this.txtMessage.Text;
                if (this.pathToFile != null)
                {
                    Attachment item = new Attachment(this.pathToFile);
                    message.Attachments.Add(item);
                }
                SmtpClient client = new SmtpClient(this.server, this.port);
                NetworkCredential credential = new NetworkCredential(this.from, this.password);
                client.UseDefaultCredentials = false;
                client.Credentials = credential;
                client.Send(message);
            }
            catch (Exception exception)
            {
                throw exception;
            }
        }

 

 

Software Developer


Tuesday, November 15, 2011 2:29 PM

Hi,

i need to download the attachment.

litu Here


Tuesday, November 15, 2011 4:26 PM

Hi,

i need to download the attachment.

litu Here

Use google/forum search.  It's there for a reason.