4

gmail からメールを読んで未読 (未読) にする方法をたくさん検索しましたが、みんなと共有したいことがわかりました。

4

2 に答える 2

5

ライブラリhttp://mailsystem.codeplex.com/を使用

ソース: http://mailsystem.codeplex.com/discussions/269058

参照を追加: activeup.net.common、activeup.net.imap4、activeup.net.mail

コード:

        Imap4Client imap = new Imap4Client();
        imap.ConnectSsl("imap.gmail.com", 993);
        imap.Login("aaaaa@gmail.com", "xxxxxxx");

        imap.Command("capability");

        Mailbox inbox = imap.SelectMailbox("inbox");
        int[] ids = inbox.Search("UNSEEN");
        if (ids.Length > 0)
        {
            ActiveUp.Net.Mail.Message msg_first = inbox.Fetch.MessageObject(ids[0]);

            //ignore this gmail_data stuff // undefined in this scope // checking to make sure it's a "new" unread msg
            //if (gmail_data != msg_first.Date.ToString())
            //{
               // gmail_data = msg_first.Date.ToString();

                XElement xmail = new XElement("gmail",
                    new XAttribute("count", ids.Length.ToString()),
                    new XAttribute("modified", msg_first.Date.ToString())
                );

                string name = "", address = "", from = "";
                Regex reg_name = new Regex("\"[^\"]+");
                Regex reg_address = new Regex("<[^>]+");

                ActiveUp.Net.Mail.Message msg = null;

                for (var i = 0; i < ids.Length; i++)
                {
                    msg = inbox.Fetch.MessageObject(ids[i]);

                    from = msg.HeaderFields["from"];
                    name = reg_name.Match(from).Value.Replace("\"", "");
                    address = reg_address.Match(from).Value.Replace("<", "");

                    xmail.Add(new XElement("entry",
                        new XAttribute("id", msg.MessageId),
                        new XAttribute("modified", msg.Date.ToString()),
                        new XAttribute("name", name),
                        new XAttribute("address", address),
                        new XElement("subject", msg.Subject),
                        new XElement("body-text", msg.BodyText.TextStripped),
                        new XElement("body-html", msg.BodyHtml.Text)
                    ));
                    //mark as unread
                    var flags = new FlagCollection();
                    flags.Add("Seen");
                    inbox.RemoveFlags(ids[i], flags);
                }


                File.WriteAllText("gmail.xml", xmail.ToString());


            }
        }
于 2013-06-19T00:33:25.730 に答える