views:

116

answers:

1

I'd like a free library for .NET to get attachments from an account (such as gMail, or others) via imap4 (not necessarely), and save them in a folder.

Ideally it would allow me to get a list of them, and download only some given ones (filtering by extension, name, and/or size) and be free.

I've already done this with a trial version of EAGetMail, but for the purpose of what i'm trying to attempt buying the unlimited version of this library isn't quite suitable (i didn't know that this functionality itself was one among the ones with limited time).

---[edit - Higuchi]---

I'm using the following code:

Dim cl As New Pop3Client()
        cl.UserName = "[email protected]"
        cl.Password = "mypassword"
        cl.ServerName = "pop.gmail.com"
        cl.AuthenticateMode = Pop3AuthenticateMode.Pop
        cl.Ssl = False
        cl.Authenticate() //takes a while, but passes even if there's a wrong password

        Dim mg As Pop3Message = cl.GetMessage(1) //gives me an exception: Message = "Pop3 connection is closed"

UPDATE: Setting the port to 995 gives me a "Response TimeOut" exception

As commented, I am having some issues while trying to connect and get the first e-mail. any help ?

+2  A: 

Well, I know you specified IMAP4, but I figured I'd offer this anyway in case POP3 is an option, since it's been useful for me:

http://csharpmail.codeplex.com/

This library provides access to POP3 mail, which many e-mail services (including Gmail) do offer in addition to the newer IMAP.

The core class is Pop3Client, which provides access to POP3 functions such as ExecuteList, ExecuteTop, etc. I have used this for specifically what you are asking about -- scanning for and downloading attachments.

If you decide this is something you could use after all and need further guidance, let me know.

UPDATE: In response to your updated question, I have just a few preliminary suggestions:

  1. Consider setting the Pop3Client.Port property to 995. I know this is what Gmail uses for POP3.
  2. The Pop3Client.Authenticate method returns a bool value indicating whether or not authentication was successful. You can check this value after calling the method to know whether it will be possible to progress further.

UPDATE 2: I tried this at home with the following settings and it worked for me:

Using client As New Pop3Client
    client.UserName = "[email protected]"
    client.Password = "[insert password here]"
    client.ServerName = "pop.gmail.com"
    client.AuthenticateMode = Pop3AuthenticateMode.Pop
    client.Ssl = True ' NOTICE: in your example code you have False here '
    client.Port = 995
    client.Authenticate()

    Dim messageList = client.ExecuteList()
    Console.WriteLine("# Messages: {0}", messageList.Count)
End Using

Try these settings and see if they work for you.

UPDATE 3: One more thing! Have you made sure to enable POP for your Gmail account? If not, you need to do that!

  1. From your Gmail inbox, click "Settings" (top right).
  2. From the Settings page, click the tab labeled "Forwarding and POP/IMAP."
  3. In the POP Download section, select one of the radio buttons to enable POP mail.
  4. Click "Save Changes" at the bottom.
Dan Tao
In fact I only pointed out the need for it to be IMAP because it's what i've been working with, and I heard it has more funcitonalities (which would maybe allow further development) but now that you've mentioned that for this specific functionality POP3 is enough, I'll certainly take a look at it! thank you again, and i'd be glad if you could help me in case I need it tomorrow (I'm about to leave now).
MarceloRamires
I've editted my question with some trouble i'm having, could you please check it out?
MarceloRamires
@MarceloRamires: I updated my answer with a couple of small suggestions. I don't know how helpful they'll be to you, though. I can probably help out in a more substantial way later tonight or tomorrow (firstly by troubleshooting the code you posted myself).
Dan Tao
@Dan Tao Setting the port to 995 gives me a "Response TimeOut" exception
MarceloRamires
@MarceloRamires: In case you're still struggling with this: did you try setting `Ssl` to `true`? This worked for me. See my update for a complete example of code that worked on my machine at home.
Dan Tao