使用emailbee在c#中从其他服务器发送电子邮件时无法找到附件

时间:2018-06-19 07:25:16

标签: c# email imap

当电子邮件来自自己的服务器时,

电子邮件附件正确下载如果邮件来自其他服务器,则附件无法下载。

private static bool ReadingMail(Imap imap)
{
    string Newconn = "";
    try
    {
        if (imap.IsConnected)
        {
             LogError("-------------------------------------------------------------", "Error_");
             LogError("connected ", "Error_");

             UidCollection uids = (UidCollection)imap.Search(true, "UNSEEN", null);
             //List<long> uids = imap.Search(Flag.Unseen);
             LogError("mail count : " + uids.Count, "Error_");
             if (uids.Count > 0)
             {
                  LogError("Number of unseen messages is: " + uids.Count, "Error_");
                  UidCollection UidTemp = new UidCollection();
                  int MaxConLimit = Convert.ToInt32(ConfigurationManager.AppSettings["MaxConLimit"]);
                  if (uids.Count >= MaxConLimit)
                  {
                       for (int k = 0; k < MaxConLimit; k++)
                       {
                            UidTemp.Add(uids[k]);
                       }
                   }
                   else
                   {
                        UidTemp = uids;
                        LogError("Number of --- unseen messages is: " + UidTemp.Count, "Error_");
                    }
                    foreach (long uid in UidTemp)
                    {
                         var message = imap.DownloadEntireMessage(uid, true);
                         message.Parser.PlainToHtmlMode = PlainToHtmlAutoConvert.IfNoHtml;
                         FileManager.SaveMessage(message, DownloadFileDir);
                          //imap.SetMessageFlags(uid, true, SystemMessageFlags.Seen, MessageFlagAction.Replace);
                          //imap.SetMessageFlags(uid.ToString(), true, SystemMessageFlags.Seen, MessageFlagAction.Remove);
                          if (IsFilePrint == "1")
                          {
                              LogError("Called PrintDownloadFile method -: ", "Error_");
                              PrintDownloadFile(); //File Print Function
                           }
                      }

                  }
                  else
                  {
                       if (IsFilePrint == "1")
                           dynammicImagePrint();
                  } 

              }
              else
              {
                   imap = new Imap();
                   Newconn = "New connection establish";
                   imap = OpenConnection();
                   ReadingMail(imap);
                }
                return true;
          }
          catch (Exception ex)
          {

               LogError("Reading Mail error: " + ex.Message + " " + Newconn, "Error_");
                return false;
          }
          finally
          {
               if (imap != null)
               {
                   if (imap.IsConnected)
                   {
                       CloseConnection(imap);
                   }
               }
          }
      }

0 个答案:

没有答案