【问题标题】:How can re enable pop in Gmail from C# code?如何从 C# 代码重新启用 Gmail 中的弹出功能?
【发布时间】:2012-05-10 07:02:05
【问题描述】:

我有一个从我的 Gmail 下载邮件的程序,我选择了单选按钮:为所有邮件启用 POP(甚至是已经下载的邮件)

在我下载邮件后,我的 Gmail 将上述状态更改为:POP 已为自当前日期以来到达的所有邮件启用

我没有实际更改单选按钮,但它看起来像是自动将其设置为仅下载新邮件。

我需要我的 windows 一直在下载。

如何在我的代码中设置 Gmail 必须始终启用所有下载?无需我每次都重新选择单选按钮。


Windows 服务

 namespace EmailWindowsService
{
    public partial class MyEmailService : ServiceBase
    {
        private static System.Timers.Timer aTimer; //Create a timer
        public MyEmailService()
        {
            InitializeComponent();
            if (!System.Diagnostics.EventLog.SourceExists("MySource")) // Log every event
            {
                System.Diagnostics.EventLog.CreateEventSource(
                    "MySource", "MyNewLog"); // Create event source can view in Server explorer
            }
            eventLogEmail.Source = "MySource";
            eventLogEmail.Log = "MyNewLog";
            // Timer Code
             aTimer = new System.Timers.Timer(1 * 60 * 1000); // 60 seconds
             aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); // Call time elapsed event
             aTimer.Enabled = true;
            // Timer Code
        }
        protected override void OnStart(string[] args)
        {
            eventLogEmail.WriteEntry("Started");
        }
        protected override void OnStop()
        {
            eventLogEmail.WriteEntry("Stopped");
        }
        protected override void OnPause()
        {
            eventLogEmail.WriteEntry("Paused");
        }
        protected override void OnContinue()
        {    
            eventLogEmail.WriteEntry("Continuing");
        }
        protected override void OnShutdown()
        {
            eventLogEmail.WriteEntry("ShutDowned");
        }
        private void OnTimedEvent(object source, ElapsedEventArgs e)
        {
            clsRetriveEmail Emails = new clsRetriveEmail();
            eventLogEmail.WriteEntry("Populateing database with mail"); // log event
            Emails.EmailGetList(); // Call class
        }       
        }
    }

namespace EmailWindowsService
{
    class clsRetriveEmail
    {
        public void EmailGetList()
        {          
            using (Pop3Client objClient = new Pop3Client())
            {
                //Athentication This is stored in the app.config file
                objClient.Connect(Properties.Settings.Default.mailServer, Properties.Settings.Default.port, Properties.Settings.Default.ssl); // mailserver eg gmail is pop.gmail.com, Port common ports 995 110 sll Security best to set to true
                objClient.Authenticate(Properties.Settings.Default.username, Properties.Settings.Default.password);  // Email Address and password
                //Count Emails and begin Looping though them
                int emailCount = objClient.GetMessageCount();
                for (int i = emailCount; i >= 1; i--)
                {
                   OpenPop.Mime.Message msg = objClient.GetMessage(i); //Get message Number. Message decleard as msg
                    //Set the values to throw into Database
                   int emailID = i;
                   String emailTo = Properties.Settings.Default.username;
                   String emailFrom = msg.Headers.From.Address;
                   String emailSubject = msg.Headers.Subject;
                   DateTime emailSentDate = msg.Headers.DateSent;
                    // The connection String can be changed in the app.config file
                    // Connect to database
                    using (var conn = new SqlConnection(Properties.Settings.Default.dbConnectionString))
                    using (var cmd = conn.CreateCommand())
                    {
                            // Writes to database (local) instance
                            conn.Open();
                            cmd.CommandText = "EmailLogFill";
                            cmd.CommandType = CommandType.StoredProcedure;
                            cmd.Parameters.AddWithValue("@id", emailID);
                            cmd.Parameters.AddWithValue("@to", emailTo);
                            cmd.Parameters.AddWithValue("@from", emailFrom);
                            cmd.Parameters.AddWithValue("@subject", emailSubject);
                            cmd.Parameters.AddWithValue("@date", emailSentDate);
                            cmd.ExecuteNonQuery();
                    }
                }
            }
        }
    }
}

【问题讨论】:

    标签: c# gmail pop3


    【解决方案1】:

    你不需要重新启用单选按钮,当一个pop客户端下载邮件时,它不能被其他pop客户端查看。 Outlook 是如何使用最近模式的。

    试试这不是您所有的邮件,而是过去 30 天的邮件。

    只需将 recent: 添加到您的用户名中,例如:recent:Me@gmail.com。

    近期模式获取最近 30 天的邮件,无论它是否已经发送到另一个 POP1 客户端。

    链接以备份它。

    http://support.google.com/mail/bin/answer.py?hl=en&answer=47948

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-13
      • 1970-01-01
      • 2022-01-20
      • 1970-01-01
      相关资源
      最近更新 更多