如何使用c#将收件箱邮件移动到gmail中的指定文件夹 [英] how to move Inbox messages to a specified folder in gmail using c#

查看:118
本文介绍了如何使用c#将收件箱邮件移动到gmail中的指定文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



i有以下代码从收件箱中检索邮件并标记为已读,但我的要求是将阅读的邮件移动到gmail中指定的文件夹。



任何人都可以为我提供解决方案。



hi
i have the following code the which retreives mails from inbox and mark as read, but my requirement is to move the read mails to the specified folder in gmail.

can any one provide me solution.

static void Main()
        {
            using (Imap imap = new Imap())
            {
          
                imap.ConnectSSL(_server);                              
                imap.Login(_user, _password);                      
                                                                   
             
                imap.SelectInbox();                               

                List<long> uids = imap.Search(Flag.Unseen);   
                
                Console.WriteLine("Number of unseen messages is: " + uids.Count);

                foreach (long uid in uids)
                {
                    IMail email = new MailBuilder().CreateFromEml(imap.GetMessageByUID(uid));

                    ProcessMessage(email);                        
                }
                imap.Close();
            }
        }







private static void ProcessMessage(IMail email)
       {
           Console.WriteLine("Subject: " + email.Subject);
           Console.WriteLine("From: " + JoinAddresses(email.From));
           Console.WriteLine("To: " + JoinAddresses(email.To));
           Console.WriteLine("Cc: " + JoinAddresses(email.Cc));
           Console.WriteLine("Bcc: " + JoinAddresses(email.Bcc));

           Console.WriteLine("Text: " + email.Text);
           Console.WriteLine("HTML: " + email.Html);

           Console.WriteLine("Attachments: ");
           foreach (MimeData attachment in email.Attachments)
           {
               Console.WriteLine(attachment.FileName);
               attachment.Save(@"c:\" + attachment.SafeFileName);
           }
       }

       private static string JoinAddresses(IList<MailBox> mailboxes)
       {
           return string.Join(",",
               new List<MailBox>(mailboxes).ConvertAll(m => string.Format("{0} <{1}>", m.Name, m.Address))
               .ToArray());
       }

       private static string JoinAddresses(IList<MailAddress> addresses)
       {
           StringBuilder builder = new StringBuilder();

           foreach (MailAddress address in addresses)
           {
               if (address is MailGroup)
               {
                   MailGroup group = (MailGroup) address;
                   builder.AppendFormat("{0}: {1};, ", group.Name, JoinAddresses(group.Addresses));
               }
               if (address is MailBox)
               {
                   MailBox mailbox = (MailBox) address;
                   builder.AppendFormat("{0} <{1}>, ", mailbox.Name, mailbox.Address);
               }
           }
           return builder.ToString();
       }
   };

推荐答案

通过以下文章可能会对你有所帮助



Read_Emails [ ]
Go through below article may it will help you

Read_Emails[]


这篇关于如何使用c#将收件箱邮件移动到gmail中的指定文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆