4

AE.NETを使用して、IMAPを使用してGmailからメールを取得しています。メッセージを取得することはできますが、メッセージの添付ファイルを繰り返し処理しようとすると、何も表示されません。message.Value.Attachments.Count()を返すと、0が返されます。

using (var imap = new AE.Net.Mail.ImapClient("imap.gmail.com", mailAccount.UserName, mailAccount.Password, AE.Net.Mail.ImapClient.AuthMethods.Login, 993, true))
{
    //Get all new messages
    var msgs = imap.SearchMessages(
        SearchCondition.Unseen()
    );
    string ret = "";

    foreach (var message in msgs)
    {
        foreach (var attachment in message.Value.Attachments)
        {
            //Save the attachment
        }
    }
}

私が言ったように、私はメールの件名とともに添付ファイルの数を記録し、メールが取得されていることを確認しましたが、添付ファイルはありません。これは、Gmailで添付ファイルを確認できるため真実ではありません。

4

3 に答える 3

2

実行しているimap.SearchMessages(SearchCondition.Unseen())のはこのメソッドだけですが、このメソッドはメールのヘッダーのみをロードします。SearchMessagesメソッドで取得したメッセージのIDで以下のコードを使用する必要があります。

List<string> ids = new List<string>();
List<AE.Net.Mail.MailMessage> mails = new List<AE.Net.Mail.MailMessage>();

using (var imap = new AE.Net.Mail.ImapClient("imap.gmail.com", mailAccount.UserName, mailAccount.Password, AE.Net.Mail.ImapClient.AuthMethods.Login, 993, true)) 
{
    var msgs = imap.SearchMessages(SearchCondition.Unseen());
    for (int i = 0; i < msgs.Length; i++) {
        string msgId = msgs[i].Uid;
        ids.Add(msgId);            
    }

    foreach (string id in ids)
    {
        mails.Add(imap.GetMessage(id, headersonly: false));
    }
}

そして、以下を使用します。

foreach(var msg in mails)
{
    foreach (var att in msg.Attachments) 
    {
        string fName;
        fName = att.Filename;
    }
}
于 2016-10-04T12:54:22.013 に答える
0
    using (var imap = new AE.Net.Mail.ImapClient("imap.gmail.com", mailAccount.UserName, mailAccount.Password, AE.Net.Mail.ImapClient.AuthMethods.Login, 993, true))  {
        var msgs = imap.SearchMessages(SearchCondition.Unseen());
        for (int i = 0; i < msgs.Length; i++) {
            MailMessage msg = msgs[i].Value;

            foreach (var att in msg.Attachments) {
                string fName;
                fName = att.Filename;
            }
        }
    }
于 2013-03-12T08:22:19.693 に答える
0

アイコン。作成者はビルド済みのダウンロードを提供していないため、自分でコンパイルする必要があります。(ただし、NuGetを使用して取得できると思います)。bin/フォルダーに.dllはもうありません。欠点と思われるドキュメントはありませんが、ソースコード(オープンソースの場合はそうです!)を確認し、Intellisenseを使用することで、これを実現することができました。次のコードは、GmailのIMAPサーバーに特に接続します。

// Connect to the IMAP server. The 'true' parameter specifies to use SSL 
// which is important (for Gmail at least) 
ImapClient ic = new ImapClient("imap.gmail.com", "name@gmail.com", "pass", ImapClient.AuthMethods.Login, 993, true); 
// Select a mailbox. Case-insensitive ic.SelectMailbox("INBOX"); Console.WriteLine(ic.GetMessageCount()); 
// Get the first *11* messages. 0 is the first message; 
// and it also includes the 10th message, which is really the eleventh ;) 
// MailMessage represents, well, a message in your mailbox 
MailMessage[] mm = ic.GetMessages(0, 10); 
foreach (MailMessage m in mm) {     
   Console.WriteLine(m.Subject); 
} // Probably wiser to use a using statement ic.Dispose();
于 2019-04-10T01:35:31.333 に答える