获取附件从邮件帐户,.NET帐户、附件、邮件、NET

2023-09-03 20:55:19 作者:我有着土匪般的热情!

我想一个免费的图书馆为.NET获得通过IMAP4从一个帐户的附件(如Gmail或其他)(未necessarely),并且将它们保存在文件夹中。

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.

我已经做到了这一点与试用版 EAGetMail ,但目的是什么我试图尝试购买无限制版本库是不太适合(我不知道这个功能本身就是一篇之中的人用有限的时间)。

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).

--- ---

我用下面的code:

Dim cl As New Pop3Client()
        cl.UserName = "marcelo.f.ramires@gmail.com"
        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"

更新:端口设置为995给了我一个响应超时异常

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 ?

推荐答案

嗯,我知道您指定IMAP4,但我想我会在情况下,POP3提供这无论如何是一个选项,因为它是有用的我:

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.$c$cplex.com/

该库提供了访问POP3邮件,其中有许多电子邮件服务(包括Gmail)献的,除了较新的IMAP。

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

核心类是 Pop3Client ,它提供了访问POP3功能,如 ExecuteList ExecuteTop ,等我用这个专门为你所要求的有关 - 扫描并下载附件

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.

更新:在回答你的更新问题,我只有几preliminary建议:

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

考虑 Pop3Client.Port 属性设置为995。我知道这是什么Gmail使用的POP3。 的 Pop3Client.Authenticate 方法返回一个布尔值指示是否验证成功。您可以调用该方法知道它是否将有可能取得进一步进展后,检查该值。 Consider setting the Pop3Client.Port property to 995. I know this is what Gmail uses for POP3. 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.

更新2 :我想这个在家里使用以下设置和它的工作对我来说:

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

Using client As New Pop3Client
    client.UserName = "username@gmail.com"
    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.

更新3 :还有一件事!你是否确信为启用POP用于Gmail帐户?如果没有,你需要做的!

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

从Gmail收件箱,点击设置(右上图)。 从设置页面,点击标有标签转发和POP / IMAP。 在POP下载部分中,选择一个单选按钮启用POP邮件。 点击保存更改在底部。