📄 unit1.cpp
字号:
//---------------------------------------------------------------------------
#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::Button1Click(TObject *Sender)
{
NMSMTP1->Host=Edit1->Text;
NMSMTP1->Port=StrToInt(Edit2->Text);
NMSMTP1->UserID=Edit3->Text;
NMSMTP1->Connect();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMSMTP1Connect(TObject *Sender)
{
StatusBar1->SimpleText="Connected";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMSMTP1ConnectionFailed(TObject *Sender)
{
ShowMessage("Connect error");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMSMTP1ConnectionRequired(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;
Form1->Button1Click(this);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMSMTP1Disconnect(TObject *Sender)
{
if (StatusBar1 != 0)
StatusBar1->SimpleText = "Disconnected";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMSMTP1EncodeEnd(AnsiString Filename)
{
StatusBar1->SimpleText = "Encoding "+Filename;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMSMTP1EncodeStart(AnsiString Filename)
{
StatusBar1->SimpleText = "Decoding "+Filename;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMSMTP1Failure(TObject *Sender)
{
ShowMessage("Operation Failed");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMSMTP1HostResolved(TComponent *Sender)
{
StatusBar1->SimpleText = "Host Resolved";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMSMTP1InvalidHost(bool &handled)
{
AnsiString NewHost;
if (InputQuery("Invalid Host", "Please Choose another host", NewHost))
{
//ShowMessage(NewHost);
NMSMTP1->Host = NewHost;
handled = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMSMTP1MailListReturn(AnsiString MailAddress)
{
Memo2->Lines->Add(MailAddress);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMSMTP1PacketSent(TObject *Sender)
{
StatusBar1->SimpleText = IntToStr(NMSMTP1->BytesSent)+" bytes of "+IntToStr(NMSMTP1->BytesTotal)+" sent";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMSMTP1RecipientNotFound(AnsiString Recipient)
{
ShowMessage(Recipient+" not found");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMSMTP1SendStart(TObject *Sender)
{
StatusBar1->SimpleText = "Sending message";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMSMTP1Status(TComponent *Sender,
AnsiString Status)
{
if (StatusBar1 != 0)
StatusBar1->SimpleText = Status;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMSMTP1Success(TObject *Sender)
{
StatusBar1->SimpleText = "Message Sent";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
NMSMTP1->Disconnect();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
if (NMSMTP1->Connected)
{
NMSMTP1->SubType = mtPlain;
switch(RadioGroup1->ItemIndex)
{
case 0:
NMSMTP1->EncodeType = uuMime;
case 1:
NMSMTP1->EncodeType = uuCode;
}
NMSMTP1->PostMessage->FromAddress=Edit5->Text;
NMSMTP1->PostMessage->FromName=Edit4->Text;
NMSMTP1->PostMessage->ToAddress->Add(Edit6->Text);
NMSMTP1->PostMessage->ToCarbonCopy->Add(Edit9->Text);
NMSMTP1->PostMessage->ToBlindCarbonCopy->Add(Edit10->Text);
NMSMTP1->PostMessage->Subject=Edit7->Text;
NMSMTP1->PostMessage->Body->Assign(Memo1->Lines);
NMSMTP1->PostMessage->Attachments->AddStrings(ListBox1->Items);
NMSMTP1->SendMail();
}
else
ShowMessage("您必须首先单击“连接”按钮连接服务器.");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
NMSMTP1->ExpandList(Edit8->Text);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button5Click(TObject *Sender)
{
if (NMSMTP1->Verify(Edit11->Text))
ShowMessage(Edit11->Text+" 存在");
else
ShowMessage(Edit11->Text+" 没有得到核实");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::AddAttachClick(TObject *Sender)
{
if (OpenDialog1->Execute())
ListBox1->Items->Add(OpenDialog1->FileName);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DelAttachClick(TObject *Sender)
{
ListBox1->Items->Delete(ListBox1->ItemIndex);
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -