procedure TMainForm.Button1Click(Sender: TObject);
var
smtp: TIdSMTP;
ssl: TIdSSLIOHandlerSocketOpenSSL;
msg: TIdMessage;
log: TIdLogEvent;
i: Integer;
begin
smtp := TIdSMTP.Create(
nil);
ssl := TIdSSLIOHandlerSocketOpenSSL.Create(
nil);
msg := TIdMessage.Create(
nil);
log := TIdLogEvent.Create(
nil);
log.OnConnect := logConnect;
log.OnDisconnect := logDisconnect;
log.OnReceived := logReceived;
log.OnSent := logSent;
log.OnStatus := logStatus;
smtp.Intercept := log;
ssl.Intercept := log;
try
try
log.Active := True;
smtp.Host := '
smtp.gmail.com';
// <- funktioniert
// mail.gmx.net <- Problem authentifizierung
smtp.Port := 587;
smtp.Username := '
USERNAME@gmail.com';
// USERNAME@gmx.at
smtp.Password := '
PASSWORD';
// PASSWORD
ssl.Host :=
smtp.Host;
ssl.Port :=
smtp.Port;
ssl.SSLOptions.Method := sslvTLSv1;
smtp.IOHandler := ssl;
smtp.UseTLS := utUseRequireTLS;
msg.Recipients.EMailAddresses := '
hans.mustermann@gmx.at';
// irgendeine Test Adresse
msg.Subject := '
This is the subject';
msg.Body.Text := '
This is the body of the email....';
smtp.Connect;
smtp.Send(msg);
smtp.Disconnect;
Memo1.Lines.Add('
*** email transfer successful ***');
log.Active := False;
finally
log.Free;
msg.Free;
ssl.Free;
smtp.Free;
end;
except
Memo1.Lines.Add('
*** email transfer not successful ***');
end;
end;
procedure TMainForm.logConnect(ASender: TIdConnectionIntercept);
begin
Memo1.Lines.Add('
*** Connect ***');
end;
procedure TMainForm.logDisconnect(ASender: TIdConnectionIntercept);
begin
Memo1.Lines.Add('
*** Disconnect ***');
end;
procedure TMainForm.logReceived(ASender: TComponent;
const AText, AData:
string);
begin
Memo1.Lines.Add(AText + '
REC: ' + AData);
end;
procedure TMainForm.logSent(ASender: TComponent;
const AText, AData:
string);
begin
Memo1.Lines.Add(AText + '
SEND: ' + AData);
end;
procedure TMainForm.logStatus(ASender: TComponent;
const AText:
string);
begin
Memo1.Lines.Add('
*** Status: ' + AText + '
***');
end;