1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
   |  
//---------------------------------------------------------------------------
 
#include <vcl.h>
#pragma hdrstop
 
#include "Unit10.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm10 *Form10;
//---------------------------------------------------------------------------
__fastcall TForm10::TForm10(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm10::Button1Click(TObject *Sender)
{
 Smtp = new TIdSMTP(NULL);
 Message = new TIdMessage(NULL);
 MemoTrace->Lines->Clear();
 Smtp->OnStatus=Status;
 Message->From->Address=lbFrom->Text;
 if(cbPrio->Checked)
   Message->Priority=mpHigh;
 Message->Subject=lbSubject->Text;
 Message->Body->Add(MemoBody->Text);
 Message->Recipients->EMailAddresses=lbTo->Text;
 try
 {
  Smtp->Host=lbHost->Text;
  Smtp->Port=StrToInt(lbPort->Text);
  Smtp->Username=lbUser->Text;
  Smtp->Password=lbPassword->Text;
  Smtp->Connect();
  Smtp->Send(Message);
 }
 catch (Exception &E)
 {
  MemoTrace->Lines->Add((E.Message));
 }
 Smtp->Disconnect(true);
 delete Message;
 delete Smtp;
 
}
//---------------------------------------------------------------------------
void __fastcall TForm10::Status(TObject *ASender, const TIdStatus AStatus,
		  const UnicodeString AStatusText)
{
	 MemoTrace->Lines->Add(AStatusText);
 
}
//---------------------------------------------------------------------------
 
 
//le .h
//---------------------------------------------------------------------------
 
#ifndef Unit10H
#define Unit10H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
#include <ExtCtrls.hpp>
#include "IdBaseComponent.hpp"
#include "IdComponent.hpp"
#include "IdExplicitTLSClientServerBase.hpp"
#include "IdMessageClient.hpp"
#include "IdSMTP.hpp"
#include "IdSMTPBase.hpp"
#include "IdTCPClient.hpp"
#include "IdTCPConnection.hpp"
#include "IdMessage.hpp"
#include "IdAntiFreeze.hpp"
#include "IdAntiFreezeBase.hpp"
//---------------------------------------------------------------------------
class TForm10 : public TForm
{
__published:	// Composants gérés par l'EDI
	TMemo *MemoBody;
	TLabel *Label1;
	TButton *Button1;
	TMemo *MemoTrace;
	TLabel *Label2;
	TGroupBox *GroupBox1;
	TLabeledEdit *lbFrom;
	TLabeledEdit *lbReplay;
	TLabeledEdit *lbSubject;
	TLabeledEdit *lbTo;
	TCheckBox *cbPrio;
	TGroupBox *GroupBox2;
	TLabeledEdit *lbHost;
	TLabeledEdit *lbPort;
	TLabeledEdit *lbUser;
	TLabeledEdit *lbPassword;
	void __fastcall Button1Click(TObject *Sender);
	void __fastcall Status(TObject *ASender, const TIdStatus AStatus, const UnicodeString AStatusText);
 
private:	// Déclarations utilisateur
	TIdSMTP* Smtp;
	TIdMessage* Message;
 
public:		// Déclarations utilisateur
	__fastcall TForm10(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm10 *Form10;
//---------------------------------------------------------------------------
#endif
 
 
//.le dfm
object Form10: TForm10
  Left = 0
  Top = 0
  Caption = 'Form10'
  ClientHeight = 690
  ClientWidth = 614
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 8
    Top = 312
    Width = 24
    Height = 13
    Caption = 'Body'
  end
  object Label2: TLabel
    Left = 8
    Top = 485
    Width = 27
    Height = 13
    Caption = 'Trace'
  end
  object MemoBody: TMemo
    Left = 8
    Top = 331
    Width = 526
    Height = 137
    ScrollBars = ssBoth
    TabOrder = 0
  end
  object Button1: TButton
    Left = 128
    Top = 628
    Width = 329
    Height = 54
    Caption = 'Send'
    TabOrder = 1
    OnClick = Button1Click
  end
  object MemoTrace: TMemo
    Left = 8
    Top = 504
    Width = 523
    Height = 98
    ScrollBars = ssVertical
    TabOrder = 2
  end
  object GroupBox1: TGroupBox
    Left = 13
    Top = 168
    Width = 526
    Height = 138
    Caption = 'Message Header'
    TabOrder = 3
    object lbFrom: TLabeledEdit
      Left = 0
      Top = 32
      Width = 121
      Height = 21
      EditLabel.Width = 24
      EditLabel.Height = 13
      EditLabel.Caption = 'From'
      TabOrder = 0
    end
    object lbReplay: TLabeledEdit
      Left = 0
      Top = 76
      Width = 121
      Height = 21
      EditLabel.Width = 27
      EditLabel.Height = 13
      EditLabel.Caption = 'Reply'
      TabOrder = 1
    end
    object lbSubject: TLabeledEdit
      Left = 0
      Top = 115
      Width = 385
      Height = 21
      EditLabel.Width = 36
      EditLabel.Height = 13
      EditLabel.Caption = 'Subject'
      TabOrder = 2
    end
    object lbTo: TLabeledEdit
      Left = 245
      Top = 32
      Width = 121
      Height = 21
      EditLabel.Width = 12
      EditLabel.Height = 13
      EditLabel.Caption = 'To'
      TabOrder = 3
    end
    object cbPrio: TCheckBox
      Left = 245
      Top = 78
      Width = 97
      Height = 17
      Caption = 'High Importance'
      TabOrder = 4
    end
  end
  object GroupBox2: TGroupBox
    Left = 13
    Top = 40
    Width = 526
    Height = 105
    Caption = 'Config'
    TabOrder = 4
    object lbHost: TLabeledEdit
      Left = 0
      Top = 32
      Width = 121
      Height = 21
      EditLabel.Width = 22
      EditLabel.Height = 13
      EditLabel.Caption = 'Host'
      TabOrder = 0
    end
    object lbPort: TLabeledEdit
      Left = 245
      Top = 32
      Width = 121
      Height = 21
      EditLabel.Width = 20
      EditLabel.Height = 13
      EditLabel.Caption = 'Port'
      TabOrder = 1
    end
    object lbUser: TLabeledEdit
      Left = 0
      Top = 81
      Width = 121
      Height = 21
      EditLabel.Width = 52
      EditLabel.Height = 13
      EditLabel.Caption = 'User Name'
      TabOrder = 2
    end
    object lbPassword: TLabeledEdit
      Left = 245
      Top = 81
      Width = 121
      Height = 21
      EditLabel.Width = 46
      EditLabel.Height = 13
      EditLabel.Caption = 'Password'
      TabOrder = 3
    end
  end
end | 
Partager