Gmail AC の添付ファイルをダウンロードするコードを実装しています。
openpop3 名前空間。このコードでは、添付ファイルのサイズをチェックしています。
サイズが指定値 (設定ファイルに kb で設定された値) より大きい場合、次のようにする必要があります。
送信者に電子メールを送信します....Windowsアプリケーションでは正常に動作しますが、コードを実装するたびに
ウィンドウサービスで問題が発生しています。このコード行から関数を終了します
OpenPop.Mime.Message m = popClient.GetMessage(i);
Framework:3.5 VS:2008 Language# Open POP 名前空間 V2.0.4.369
This is my code
 OpenPop.Mime.Message m = popClient.GetMessage(i);
private void ReceiveMails()
    {
            Utility.Log = true;
            if (popClient.Connected)
            {
                popClient.Disconnect();
            }
            popClient.Connect(POPServer, port, ssl);
            popClient.Authenticate(username, password);
            int Count = popClient.GetMessageCount();
            writeToLogFile("Total Mail count is:" + Count.ToString());
            if (Count > 0)
            {
                for (int i = 1; i <= Count; i++)
                {
                    flag = false;
                    OpenPop.Mime.Message m = popClient.GetMessage(i);
                    Sub = m.Headers.Subject;
                   int size = popClient.GetMessageSize(i);
                    int mailsize = int.Parse(ConfigurationSettings.AppSettings
["emailSize"]) * 1024;
                    if (size < mailsize)
                    {
                    //we are checking the sub of Email
                    for (int j = 1; j < 30; j++)
                    {
                        strFranchisekey = ConfigurationSettings.AppSettings
["Franchise" + j];
                        if (strFranchisekey != "")
                        {
                            int inex = strFranchisekey.IndexOf("=");
                            strFranchiseshortvalue = strFranchisekey.Substring
(0, inex);
                            if (Sub.Contains(strFranchiseshortvalue))
                            {
                                flag = true;
                                foreach (OpenPop.Mime.MessagePart attachment in 
m.FindAllAttachments())
                                {
                                    writeToLogFile(attachment.FileName);
                                    file = attachment.FileName;
                                    index = strFranchisekey.IndexOf("=");
                                    string StrCity = strFranchisekey.Substring
(index + 1);
                                    strFolderPath = 
(ConfigurationSettings.AppSettings["FolderPath" +StrCity]);
                                    StrSubFolderPath = 
(ConfigurationSettings.AppSettings["SubPath" + StrCity]);
                                    if (Directory.Exists(strFolderPath))
                                    //we are checking folder exists or not ?
                                    {
                                        File.WriteAllBytes(strFolderPath + "\\" 
+ file, attachment.Body);
                                    }
                                    //
                                    else if (Directory.Exists
(StrSubFolderPath))
                                    {
                                        File.WriteAllBytes(StrSubFolderPath + 
"\\" + file, attachment.Body);
                                    }
                                    else
                                    {
                                        //we can give here invalid path.
                                        File.WriteAllBytes
(ConfigurationSettings.AppSettings["InvalidPath"] + "\\" + file, attachment.Body);
                                        sendEmail(i);
                                    }
                                }
                                break;
                            }
                        }
                    }
                    if (flag != true)
                    {
                        writeToLogFile("matching franchise name is not found");
                        foreach (OpenPop.Mime.MessagePart attachment in 
m.FindAllAttachments())
                        {
                            File.WriteAllBytes
(ConfigurationSettings.AppSettings["InvalidPath"] + "\\" + file, attachment.Body);
                        }
                        sendEmail(i);
                    }
                }
             }
    else
  {
     writeToLogFile("Please reduce the  email size");
   }
            }
            else
            {
                writeToLogFile("No New Attachment");
            }
        }