procedure TfrmMain.InitSendMail;
begin
// Komponenten erzeugen
if not Assigned(IndySMTP) then IndySMTP := TIdSMTP.Create(Application);
if not Assigned(IndyMessage) then IndyMessage := TIdMessage.Create(Application);
if not Assigned(IndySSLHandler) then IndySSLHandler := TIdSSLIOHandlerSocketOpenSSL.Create(Application);
if not cbSSL.Checked then
begin
IndySMTP.IOHandler := nil; // nicht benötigt
IndySMTP.UseTLS := utNoTLSSupport;
end
else
begin
// SSLHandler inititlisieren
IndySSLHandler.MaxLineAction := maException;
IndySSLHandler.SSLOptions.Method := sslvTLSv1;
IndySSLHandler.SSLOptions.Mode := sslmUnassigned;
IndySSLHandler.SSLOptions.VerifyMode := [];
IndySSLHandler.SSLOptions.VerifyDepth := 0;
IndySMTP.IOHandler := IndySSLHandler;
end;
// Verbindungsdaten setzen
IndySMTP.Host := edtHost.Text;
IndySMTP.Port := StrToInt(edtPort.Text);
if cbSSL.Checked then
begin
// https://forums.embarcadero.com/message.jspa?messageID=528772
if cbbSSLType.Text = 'Explicit' then IndySMTP.UseTLS := utUseExplicitTLS;
if cbbSSLType.Text = 'Implicit' then IndySMTP.UseTLS := utUseImplicitTLS;
if cbbSSLType.Text = 'Require' then IndySMTP.UseTLS := utUseRequireTLS;
end;
if (edtUser.Text = '') and (edtPassword.Text = '') then
IndySMTP.AuthType := satNone
else begin
IndySMTP.AuthType := satDefault;
IndySMTP.Username := edtUser.Text;
IndySMTP.Password := edtPassword.Text;
end;
end;
function TfrmMain.SendMail: String;
begin
Result := '';
Screen.Cursor := crHourGlass;
try
with IndyMessage do
begin
Clear;
From.Name := edtSender.Text;
From.Address := edtSenderAdress.Text;
Recipients.EMailAddresses := edtRecipient.Text;
Subject := edtSubject.Text;
ContentType := 'Multipart/Alternative';
Body := mmMessage.Lines;
end;
// mit
SMTP verbinden
IndySMTP.Connect;
if IndySMTP.Connected then
begin
IndySMTP.Send(IndyMessage);
IndySMTP.Disconnect;
MessageDlg('Die E-Mail wurde erfolgreich versandt.', mtInformation, [mbOK], 0);
end;
except
on E:
Exception do
begin
Result := E.Message;
if IndySMTP.Connected then IndySMTP.Disconnect;
end;
end;
Screen.Cursor := crDefault;
end;