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

📄 unit1.cpp

📁 <<C++Builder 6实用编程100例>>随书光盘
💻 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->UserID=Edit2->Text;
        NMSMTP1->Connect();
        GroupBox1->Enabled=true;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)
{
        SYSTEMTIME *GTL;
        GTL=new SYSTEMTIME;
        GetLocalTime(GTL);
        Edit9->Text=String(GTL->wYear)+'-'+String(GTL->wMonth)+'-'+String(GTL->wDay)+' '
                +String(GTL->wHour)+':'+String(GTL->wMinute)+':'+String(GTL->wSecond);
        NMSMTP1->SubType=mtPlain;
        NMSMTP1->PostMessage->FromAddress=Edit3->Text;
        NMSMTP1->PostMessage->FromName=Edit4->Text;
        NMSMTP1->PostMessage->ToAddress->Text=Edit5->Text;
        NMSMTP1->PostMessage->ToCarbonCopy->Text=Edit7->Text;
        NMSMTP1->PostMessage->ToBlindCarbonCopy->Text=Edit8->Text;
        NMSMTP1->PostMessage->Body->Text=Memo1->Text;
        NMSMTP1->PostMessage->Attachments->Text=ListBox1->Items->Text;
        NMSMTP1->PostMessage->Subject=Edit6->Text;
        NMSMTP1->PostMessage->Date=Edit9->Text;
        NMSMTP1->SendMail();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ListBox1KeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
        if(Key==VK_INSERT)
                if(OpenDialog1->Execute())
                        ListBox1->Items->Add(OpenDialog1->FileName);
        if(Key==VK_DELETE)
                ListBox1->Items->Delete(ListBox1->ItemIndex);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMSMTP1AttachmentNotFound(AnsiString Filename)
{
        StatusBar1->SimpleText="附件"+Filename+"不存在。";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMSMTP1AuthenticationFailed(bool &Handled)
{
        AnsiString S;
        S=NMSMTP1->UserID;
        if (InputQuery("用户登陆失败","请重新输入用户名:",S))
        {
                NMSMTP1->UserID=S;
                Handled=true;
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMSMTP1Connect(TObject *Sender)
{
        StatusBar1->SimpleText="服务器连接成功。";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMSMTP1SendStart(TObject *Sender)
{
        StatusBar1->SimpleText="开始发送邮件。";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMSMTP1EncodeStart(AnsiString Filename)
{
        StatusBar1->SimpleText="附件开始编码"+Filename;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMSMTP1EncodeEnd(AnsiString Filename)
{
        StatusBar1->SimpleText=Filename+"附件编码结束。";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMSMTP1Failure(TObject *Sender)
{
        StatusBar1->SimpleText="邮件发送失败。";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMSMTP1Success(TObject *Sender)
{
        StatusBar1->SimpleText="邮件发送成功。";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMSMTP1HeaderIncomplete(bool &handled, int hiType)
{
        AnsiString S;
        switch(hiType)
        {
                case hiFromAddress:
                {
                        if(InputQuery("发件人错误","请重新输入:",S))
                        {
                                NMSMTP1->PostMessage->FromAddress=S;
                                handled=true;
                        }
                }
                case hiToAddress:
                {
                        if(InputQuery("收件人错误","请重新输入:",S))
                        {
                                NMSMTP1->PostMessage->ToAddress->Text=S;
                                handled=true;
                        }
                }
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMSMTP1RecipientNotFound(AnsiString Recipient)
{
        StatusBar1->SimpleText="收件人"+Recipient+"不存在。";        
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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