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
| //---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit5.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
IdMsgSend = new TIdMessage(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
IdMsgSend->Clear();
IdMsgSend->ContentType = "Multipart/Alternative";
IdMsgSend->Subject = "Sujet du message";
// add a plain text message part
TIdText *idtTextPart = new TIdText(IdMsgSend->MessageParts,NULL);
idtTextPart->ContentType = "text/plain";
idtTextPart->Body->Add("This is the plain part of the message.");
TStringList* body = new TStringList();
body->Add("Test");
// add the HTML message part
idtTextPart = new TIdText(IdMsgSend->MessageParts,body);
idtTextPart->ContentType = "text/html";
IdMsgSend->From->Address = "me@mycompany.com";
IdMsgSend->From->Name = "Me";
IdMsgSend->Sender->Address = "me@mycompany.com";
IdMsgSend->Sender->Name = "Me";
// add the recipients TIdEmailAddressList
IdMsgSend->Recipients->Clear();
IdMsgSend->Recipients->Add()->Address = "address1@somecompany.com";
IdMsgSend->Recipients->Add()->Address = "address2@somecompany.com";
IdMsgSend->Subject = "Some Subject";
// add an attachment
TIdAttachment* attachment = new TIdAttachment(IdMsgSend->MessageParts, "C:\\Documents and Settings\\alexandrep\\Mes documents\\Mes images\\fleche.JPG");
SMTP->Host = "smtp.isp.com";
SMTP->Port = 25;
SMTP->Connect();
bool test = SMTP->Connected();
bool test2 = SMTP->Authenticate();
SMTP->Send(IdMsgSend);
SMTP->Disconnect();
ShowMessage("Message Sent");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
delete IdMsgSend;
}
//--------------------------------------------------------------------------- |
Partager