簡體   English   中英

AE.Net.Mail 連接超時

[英]AE.Net.Mail connection timing out

我正在創建一個必須閱讀電子郵件並將其寫入文本文件的程序。 我選擇使用 AE.Net.Mail nuget package 來執行此操作。 但是,當我嘗試閱讀電子郵件時,連接超時。 這是讀取電子郵件的代碼:

IC = new ImapClient("imap.gmail.com", yourEmail, yourPassword, AuthMethods.Login, 993, true);

IC.SelectMailbox("INBOX");
var Email = IC.GetMessage(-1);

string body = Email.Body;

調用 IC.GetMessage(-1) 時超時。 這是什么原因?

檢查它會工作

public string ParseNewEmail()
            {
                // Connect to the IMAP server. The 'true' parameter specifies to use SSL, which is important (for Gmail at least)
                ImapClient imapClient = new ImapClient(ConfigurationManager.AppSettings["ImapServer"], ConfigurationManager.AppSettings["UserId"], ConfigurationManager.AppSettings["Password"], AuthMethods.Login, 993, true);
                var userName = ConfigurationManager.AppSettings["UserID"];
              //  ImapClient imapClient = new ImapClient(ConfigurationManager.AppSettings["ImapServer"], "jayasreetestemail@gmail.com", "7Ywy7N[S", AuthMethods.Login, 993, true);
                // Select a mailbox. Case-insensitive
                imapClient.SelectMailbox("INBOX");
                string emailJson="";          
                imapClient.NewMessage += (sender, e) =>
                {
                    var msg = imapClient.GetMessage(e.MessageCount - 1);
                    UpdatePackage up = new UpdatePackage();
                    up.Updates = ParseBody(msg.Body);
                    up.Subject = msg.Subject;
                    up.Body = msg.Body;
                    up.ProjectName = ApplicationName;              
                   
                  emailJson = JsonConvert.SerializeObject(up);                          
                  string result = "";
                  using (var client = new WebClient())
                  {
                      client.Headers[HttpRequestHeader.ContentType] = "application/json";
                     // result = client.UploadString("https://localhost:44300/ProjectUpdate/Update", "Post", emailJson);
                      result = client.UploadString("https://costcodevops.azurewebsites.net/ProjectUpdate/Update", "Post", emailJson);
                      Console.WriteLine(result);
                  }
                  
                   
                };           
    
               return emailJson;           
            }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM