Mail Attachment

Aug 6, 2009 at 11:39 AM

Hi,

How to get the status of one mail attachment status ? Means I want to get a boolean value for whether any attachment is present in a particular mail.

If any attachment exists, How to count the number of attachments & download them to local disk ?

 

Coordinator
Aug 10, 2009 at 3:45 AM

You can filter attachment files with this method in Pop3Message class.

public static List<Pop3Content> GetAttachedContents(List<Pop3Content> inContents, Predicate<Pop3Content> inPredicate)

-----sample-------

Pop3Message mg = ....;//get Pop3Message object with Pop3Client class

List<Pop3Content> contentList = Pop3Message.GetAttachedContents(mg.Contents, c => c.IsAttachment == true);

Int32 AttachmentCount = contentList.Count;

for (int i=0; i<contentList.Count; i++)
{

    contentList[i].DecodeData("your file path");

}

 

 

 

 

Feb 21, 2010 at 4:30 AM
Edited Feb 21, 2010 at 4:37 AM

Hi,

I'm trying to download an attachment from an email (server is an Exchange 2007 SP1)

 

Here is what I'm using and the error I´m getting

 

Code:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Higuchi.Net;
using Higuchi.Net.Mail;
using Higuchi.Net.Pop3;

namespace GetMailAttachment
{
class Program
{
static void Main(string[] args)
{
Pop3Client cl = new Pop3Client();
//{ cl.UserName = "mail@domain.com";
cl.Password = "MyPassword";
cl.ServerName = "owa.domain.com"; cl.AuthenticateMode = Pop3AuthenticateMode.Pop; cl.Ssl = false;
cl.Authenticate();
///Get first mail of my mailbox Pop3Message mg = cl.GetMessage(1); List<Pop3Content> contentList = Pop3Message.GetAttachedContents(mg.Contents, c => c.IsAttachment == true);
Int32 AttatchmentCount = contentList.Count;
Console.WriteLine("Attatchment count: " + AttatchmentCount);
System.Threading.Thread.Sleep(2500);
String MyText = mg.BodyText;
Console.WriteLine(MyText);
                System.Threading.Thread.Sleep(2500);
                ///If the message have one attachment
                //Pop3Content ct = mg.Contents[1];
                ///you can save it to local disk
                //string fn;
                //fn = ct.FileName.ToString();
                //Console.WriteLine(fn);
                contentList[0].DecodeData(@"c:\");
                //ct.DecodeData(@"C:\");
                System.Threading.Thread.Sleep(2500);
            
        }
    }
}

 

 

Here is the Error:

System.UnauthorizedAccessException was unhandled
  Message="Acceso denegado a la ruta de acceso 'c:\\'."             <<<<<<<<<<<<<<<<<<<<<<<<-------------------- This means access denied to C:\
  Source="mscorlib"
  StackTrace:
       en System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
       en System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
       en System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
       en System.IO.FileStream..ctor(String path, FileMode mode)
       en Higuchi.Net.MimeContent.DecodeData(String inFilePath)
       en GetMailAttachment.Program.Main(String[] args) en C:\Users\laptop\Documents\Visual Studio 2008\Projects\BillingAutomation\GetMailAttachment\Program.cs:línea 38
  InnerException:

 

Kindly let me know what I'm doing wrong here

Thanks in advance.

Regards,

Jose

Coordinator
Feb 27, 2010 at 11:50 AM

Modify this code
contentList[0].DecodeData(@"c:\");
as below
contentList[0].DecodeData(@"c:\mydata.txt");

or check that you have permission to C drive.

regard.