⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pop3_c.cpp

📁 BCB编写的使用SMTP、POP3和FTP的例子
💻 CPP
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Pop3_c.h"
//---------------------------------------------------------------------------
#pragma resource "*.dfm"
TPop3Form *Pop3Form;
//---------------------------------------------------------------------------
__fastcall TPop3Form::TPop3Form(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TPop3Form::Button1Click(TObject *Sender)
{
  NMPOP31->AttachFilePath = ".";
  NMPOP31->DeleteOnRead = false;
  NMPOP31->ReportLevel = Status_Basic;
  NMPOP31->TimeOut = 20000;
  NMPOP31->Host = Edit1->Text;
  NMPOP31->Port = StrToInt(Edit2->Text);
  NMPOP31->UserID = Edit3->Text;
  NMPOP31->Password = Edit4->Text;
  NMPOP31->Connect();
  Label10->Caption = "# of Messages: "+IntToStr(NMPOP31->MailCount);
}
//---------------------------------------------------------------------------
void __fastcall TPop3Form::Button2Click(TObject *Sender)
{
  NMPOP31->Disconnect();	
}
//---------------------------------------------------------------------------
void __fastcall TPop3Form::Button5Click(TObject *Sender)
{
  NMPOP31->List();	
}
//---------------------------------------------------------------------------
void __fastcall TPop3Form::Button4Click(TObject *Sender)
{
  Memo3->Clear();
}
//---------------------------------------------------------------------------
void __fastcall TPop3Form::Button7Click(TObject *Sender)
{
  NMPOP31->DeleteMailMessage(StrToInt(Edit5->Text));	
}
//---------------------------------------------------------------------------
void __fastcall TPop3Form::Button3Click(TObject *Sender)
{
  NMPOP31->GetMailMessage(StrToInt(Edit5->Text));
  Edit6->Text = NMPOP31->MailMessage->From;
  Edit7->Text = NMPOP31->MailMessage->Subject;
  Edit9->Text = NMPOP31->MailMessage->MessageId;
  Memo2->Lines->Assign(NMPOP31->MailMessage->Head);
  Memo1->Lines->Assign(NMPOP31->MailMessage->Body);
  if (NMPOP31->MailMessage->Attachments->Text != "")
  {
    Button8->Enabled  = true;
    ShowMessage("Attachments:\n"+NMPOP31->MailMessage->Attachments->Text);
  }
  else
    Button8->Enabled  = false;
}
//---------------------------------------------------------------------------
void __fastcall TPop3Form::Button6Click(TObject *Sender)
{
  NMPOP31->GetSummary(StrToInt(Edit5->Text));
  Edit6->Text = NMPOP31->Summary->From;
  Edit7->Text = NMPOP31->Summary->Subject;
  Edit8->Text = IntToStr(NMPOP31->Summary->Bytes);
  Edit9->Text = NMPOP31->Summary->MessageId;
}
//---------------------------------------------------------------------------
void __fastcall TPop3Form::NMPOP31Connect(TObject *Sender)
{
  StatusBar1->SimpleText = "Connected";	
}
//---------------------------------------------------------------------------
void __fastcall TPop3Form::NMPOP31ConnectionFailed(TObject *Sender)
{
  ShowMessage("Connection Failed");
}
//---------------------------------------------------------------------------
void __fastcall TPop3Form::NMPOP31ConnectionRequired(bool &handled)
{
  AnsiString BoxCaption;
  AnsiString BoxMsg;
  BoxCaption = "Connection Required";
  BoxMsg = "Connection Required. Connect?";
  if (MessageBox(0, &BoxMsg[1], &BoxCaption[1], MB_YESNO + MB_ICONEXCLAMATION) == IDYES)
  {
    handled = TRUE;
    Pop3Form->Button1Click(this);
  }  
}
//---------------------------------------------------------------------------
void __fastcall TPop3Form::NMPOP31Disconnect(TObject *Sender)
{
  if (StatusBar1 != 0)
    StatusBar1->SimpleText = "Disconnected";	
}
//---------------------------------------------------------------------------
void __fastcall TPop3Form::NMPOP31Failure(TObject *Sender)
{
  ShowMessage("Operation failed");
}
//---------------------------------------------------------------------------
void __fastcall TPop3Form::NMPOP31HostResolved(TComponent *Sender)
{
  StatusBar1->SimpleText = "Host Resolved";	
}
//---------------------------------------------------------------------------
void __fastcall TPop3Form::NMPOP31InvalidHost(bool &handled)
{
  AnsiString NewHost;
  if (InputQuery("Invalid Host", "Please Choose another host", NewHost))
  {
    //ShowMessage(NewHost);
    NMPOP31->Host = NewHost;
    handled = true;
  }
}
//---------------------------------------------------------------------------
void __fastcall TPop3Form::NMPOP31List(int Msg, int Size)
{
  if (Msg < 2)
  {
    Memo3->Clear();
    Memo3->Lines->Add("Message Number / Message Size");
  }
  Memo3->Lines->Add(IntToStr(Msg)+" / "+IntToStr(Size));
}
//---------------------------------------------------------------------------
void __fastcall TPop3Form::NMPOP31PacketRecvd(TObject *Sender)
{
  StatusBar1->SimpleText = IntToStr(NMPOP31->BytesRecvd)+" bytes of "+IntToStr(NMPOP31->BytesTotal)+" Received";	
}
//---------------------------------------------------------------------------
void __fastcall TPop3Form::NMPOP31Reset(TObject *Sender)
{
  ShowMessage("Delete Flags Reset");	
}
//---------------------------------------------------------------------------
void __fastcall TPop3Form::NMPOP31RetrieveEnd(TObject *Sender)
{
  Pop3Form->Cursor = crDefault;
  StatusBar1->SimpleText = "Retrieval complete";
}
//---------------------------------------------------------------------------
void __fastcall TPop3Form::NMPOP31RetrieveStart(TObject *Sender)
{
  Pop3Form->Cursor = crHourGlass;
  StatusBar1->SimpleText = "Beginning message retrieval";
}
//---------------------------------------------------------------------------
void __fastcall TPop3Form::NMPOP31Status(TComponent *Sender, AnsiString Status)
{
  if (StatusBar1 != 0)
    StatusBar1->SimpleText = Status;
}
//---------------------------------------------------------------------------
void __fastcall TPop3Form::NMPOP31Success(TObject *Sender)
{
  StatusBar1->SimpleText = "Operation Successful";	
}
//---------------------------------------------------------------------------

void __fastcall TPop3Form::Button8Click(TObject *Sender)
{
        if(SaveDialog1->Execute())
                NMPOP31->MailMessage->Attachments->SaveToFile(SaveDialog1->FileName);
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -