Суббота, 18.05.2024, 20:52
Главная Регистрация RSS
Приветствую Вас, Гость
Меню сайта
Категории раздела
Форма входа
ДРУЗЬЯ САЙТА

Вызвать мастера в Красноярске

8 983 207 5474

8 902 918 9334

8 933 332 3164

---------------------------------

Запчасти бытткхники

  • Велес т.2935600
  • СЦ Близнецов т.2296595
  • Вираж
  • Красраб 110 т.2589503
  • Комплекстур Щорса30 т.2606797
  • Радиодетали

  • Якорный 9 т.2688317
  • Воронова 16 т.2202990
  • Красраб 125а т.2456544
  • Профи т.2702737
  • Дайте две т.+79237713323
  • Электрика

  • Электро +
  • Планета электрика
  • ЗАКЛАДКИ
    Поиск
    Статистика

    Онлайн всего: 1
    Гостей: 1
    Пользователей: 0
    Главная » Статьи » C++ Builder » Простые примеры

    C++ BUILDER XE2 INDY 10 IdPOP3 читаем почту
    Для работы с Яндекс почтой 
    Нужно в настройках почтового ящика: Почта->Настройка->Почтовые программы
     Разрешить доступ к почтовому ящику с помощью почтовых клиентов поставить галку  С сервера pop.yandex.ru по протоколу POP3 


    ---------------------------------------------------------------------
    ---------------------------------------------------------------------
    //---------------------------------------------------------------------------

    #include <vcl.h>
    #pragma hdrstop

    #include "Unit1.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
    {
    }
    //------При уничтожении формы отключаемся---------------------------------------------------------------------
    void __fastcall TForm1::FormDestroy(TObject *Sender)
    {
    if(IdPOP31->Connected()) IdPOP31->Disconnect();
    }
    //-----Загружаем почту----------------------------------------------------------------------
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
     if( Edit1->Text != "" && Edit2->Text != "" && Edit3->Text != "" && Edit4->Text != "" ){  //0
     Memo1->Lines->Clear();
     ListBox1->Items->Clear();
     ListView1->Items->Clear();
     int MailCount = 0;
     if(IdPOP31->Connected()) IdPOP31->Disconnect();
     IdPOP31->Host = Edit1->Text ;
     IdPOP31->Port = StrToIntDef( Edit2->Text, 110 ) ;
     IdPOP31->Username = Edit3->Text ;
     IdPOP31->Password = Edit4->Text ;
     IdPOP31->ConnectTimeout=60000;
     IdPOP31->ReadTimeout=60000;
     IdPOP31->Connect();

      MailCount = IdPOP31->CheckMessages();
      if(MailCount > 0){ //1
      int c = 0;
      for(int i = 1; i <= MailCount; i++){
      IdMessage1->Clear();
      IdMessage1->ClearBody();
      IdMessage1->MessageParts->Clear();
      if(IdPOP31->Retrieve(i, IdMessage1)){ //3
      ListView1->Items->Add();
      ListView1->Items->Item[c]->Caption =IdMessage1->From->Text;
      ListView1->Items->Item[c]->SubItems->Add(IdMessage1->Subject);
      ListView1->Items->Item[c]->SubItems->Add(DateToStr( IdMessage1->Date ) );
      c++ ;
    } //3
    } //2
     } //1
      return ;
      } ShowMessage("Заполни поля: хост, порт, логин, пароль"); //0
    }

    //--------Выбираим и открываем письмо-------------------------------------------------------------------
    void __fastcall TForm1::ListView1SelectItem(TObject *Sender, TListItem *Item, bool Selected)

    {
    if( ListView1->Selected != 0 ){//1
     UnicodeString FileName;
     TIdAttachmentFile *IdAttach[10];
     TIdText *itex;
     Memo1->Lines->Clear();
     ListBox1->Items->Clear();
     IdMessage1->Clear();
     IdMessage1->ClearBody();
     IdMessage1->MessageParts->Clear();
     if(IdPOP31->Retrieve(ListView1->Selected->Index+1 , IdMessage1)){ //3
     Memo1->Text = IdMessage1->Body->Text ;
     int PartCount = IdMessage1->MessageParts->Count;
      for( int p = 0; p < PartCount; p++){  //5
     if(IdMessage1->MessageParts->Items[p]->ClassNameIs("TIdAttachmentFile")){ //6
     IdAttach[p] = (TIdAttachmentFile*) IdMessage1->MessageParts->Items[p];
     FileName = IdAttach[p]->FileName;
     ListBox1->Items->AddObject(FileName,IdAttach[p] );
     } //6
     if(IdMessage1->MessageParts->Items[p]->ClassNameIs("TIdText")){ //16
     itex = (TIdText*) IdMessage1->MessageParts->Items[p];
     //ListBox1->Items->Add(itex->ContentType );
     Memo1->Text = itex->Body->Text;
     } //16
    } //5
      }//3
    }//1
    }

    //---------Выбираем и сохраняем прикреплённые файлы------------------------------------------------------------------
    void __fastcall TForm1::ListBox1Click(TObject *Sender)
    {
     if(ListBox1->ItemIndex > -1 ) {
      UnicodeString  FileName;
      TIdAttachmentFile *IdAttach;
      int p = ListBox1->ItemIndex + 1 ;
      IdAttach = ((TIdAttachmentFile *)ListBox1->Items->Objects[ListBox1->ItemIndex]);
      FileName = IdAttach->FileName;
      SaveDialog1->FileName = FileName;
      if(SaveDialog1->Execute() ) {
      IdAttach->SaveToFile(SaveDialog1->FileName );
     }
    }
    }
    //----------данный обработчик не используется в программе-----------------------------------------------------------------
    void __fastcall TForm1::ListView1MouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift,
     int X, int Y)
    {
    if( ListView1->Selected != 0 ){
    UnicodeString str = ListView1->GetItemAt(X,Y)->SubItems->Strings[1] ;
    }
    }
    //---------------------------------------------------------------------------



    //---------------------------------------------------------------------------

    #ifndef Unit1H
    #define Unit1H
    //---------------------------------------------------------------------------
    #include <System.Classes.hpp>
    #include <Vcl.Controls.hpp>
    #include <Vcl.StdCtrls.hpp>
    #include <Vcl.Forms.hpp>
    #include <IdBaseComponent.hpp>
    #include <IdComponent.hpp>
    #include <IdExplicitTLSClientServerBase.hpp>
    #include <IdMessage.hpp>
    #include <IdMessageClient.hpp>
    #include <IdPOP3.hpp>
    #include <IdTCPClient.hpp>
    #include <IdTCPConnection.hpp>
    #include <IdText.hpp>
    #include <IdAttachmentFile.hpp>
    #include <Vcl.ExtCtrls.hpp>
    #include <Vcl.Dialogs.hpp>
    #include <Vcl.ComCtrls.hpp>
    //---------------------------------------------------------------------------
    class TForm1 : public TForm
    {
    __published: // IDE-managed Components
    TIdPOP3 *IdPOP31;
    TIdMessage *IdMessage1;
    TMemo *Memo1;
    TButton *Button1;
    TPanel *Panel1;
    TPanel *Panel2;
    TPanel *Panel3;
    TPanel *Panel4;
    TPanel *Panel5;
    TSaveDialog *SaveDialog1;
    TListView *ListView1;
    TEdit *Edit1;
    TSplitter *Splitter1;
    TEdit *Edit2;
    TEdit *Edit3;
    TEdit *Edit4;
    TListBox *ListBox1;
    TLabel *Label1;
    TLabel *Label2;
    TLabel *Label3;
    TLabel *Label4;
    void __fastcall Button1Click(TObject *Sender);
    void __fastcall FormDestroy(TObject *Sender);
    void __fastcall ListView1SelectItem(TObject *Sender, TListItem *Item, bool Selected);
    void __fastcall ListView1MouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift,
              int X, int Y);
    void __fastcall ListBox1Click(TObject *Sender);

    private: // User declarations
    public: // User declarations
    __fastcall TForm1(TComponent* Owner);
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TForm1 *Form1;
    //---------------------------------------------------------------------------
    #endif




    Категория: Простые примеры | Добавил: doka (08.05.2012)
    Просмотров: 4529 | Рейтинг: 1.0/1
    Добавлять комментарии могут только зарегистрированные пользователи.
    [ Регистрация | Вход ]