Na formu postavite TIdSMTP(SMTP1) i TIdMessage(M1) komponentu. Dodajte i sljedeće TEdit komponente (opcionalno):
ESMTP - lokacija smtp servera
EPort - port za smtp (25)
ESubject - subject poruke
ESalje - tko šalje poruku (povratna e-mail adresa)
Memo1 - tekst poruke
EPrilog - puna lokacija datoteke koja se šalje kao prilog (attachment)
...i naravno gumb Button1 kojim ćemo aktivirati slanje e-maila.
Code:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TIdAttachment *Prilog;
SMTP1->Host = ESMTP->Text;
SMTP1->Port = StrToInt(EPort->Text);
M1->Subject = ESubject->Text;
M1->From->Address = ESalje->Text;
M1->Body->Add(Memo1->Text);
M1->Recipients->EMailAddresses = EPrima->Text;
if(EPrilog->Text.Length() > 0)
Prilog = new TIdAttachment(M1->MessageParts, EPrilog->Text);
try
{
SMTP1->Connect();
SMTP1->Send(M1);
}
catch(Exception &e) {
MessageBox(0, e.Message.c_str(),0,0);
}
SMTP1->Disconnect();
if(EPrilog->Text.Length() > 0)
delete Prilog;
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TIdAttachment *Prilog;
SMTP1->Host = ESMTP->Text;
SMTP1->Port = StrToInt(EPort->Text);
M1->Subject = ESubject->Text;
M1->From->Address = ESalje->Text;
M1->Body->Add(Memo1->Text);
M1->Recipients->EMailAddresses = EPrima->Text;
if(EPrilog->Text.Length() > 0)
Prilog = new TIdAttachment(M1->MessageParts, EPrilog->Text);
try
{
SMTP1->Connect();
SMTP1->Send(M1);
}
catch(Exception &e) {
MessageBox(0, e.Message.c_str(),0,0);
}
SMTP1->Disconnect();
if(EPrilog->Text.Length() > 0)
delete Prilog;
}
...a ovo je source code.