function MeinMailVersand(
const aAbsender,
aMailCopyTo,
aUserName,
aHost,
aPassword,
aEmpfaenger,
aSubject,
aTextBody,
aHtmlBody,
aDateianlage:
string;
var aMsg:
string) : boolean;
var
Html: TStrings;
HtmPart, TxtPart: TIdText;
SMTP: TIdSMTP;
BmpPart: TIdAttachmentFile;
EMail: TIdMessage;
begin
aMsg := '
';
Result := false;
EMail :=
nil;
Html :=
nil;
SMTP :=
nil;
try
SMTP := TIdSMTP.Create;
Html := TStringList.Create;
EMail := TIdMessage.Create(
nil);
{-HTML-Daten-}
Html.Add('
<html>');
Html.Add('
<head>');
Html.Add('
</head>');
Html.Add('
<body>'+aHtmlBody);
Html.Add('
<img src="cid:us.jpg" />');
Html.Add('
</body>');
Html.Add('
</html>');
{-Mail-Daten-}
EMail.From.Address := aAbsender;
EMail.Recipients.EMailAddresses := aEmpfaenger;
EMail.Subject := aSubject;
EMail.ContentType := '
multipart/mixed';
EMail.Body.Assign(
Html);
{-Lesebestätigung-}
EMail.ExtraHeaders.AddValue('
Disposition-Notification-To', aAbsender);
{-Text-Part-}
if aTextBody <> '
'
then begin
TxtPart := TIdText.Create(email.MessageParts);
TxtPart.ContentType := '
text/plain';
TxtPart.Body.Text := aTextBody;
end;
{-Dateianlage-}
HtmPart := TIdText.Create(email.MessageParts,
html);
HtmPart.ContentType := '
text/html';
BmpPart := TIdAttachmentFile.Create(EMail.MessageParts, aDateianlage);
BmpPart.ContentType := '
image/jpeg';
BmpPart.ContentDisposition := '
inline';
BmpPart.ExtraHeaders.Values['
content-id'] := '
us.jpg';
BmpPart.DisplayName := '
us.jpg';
{-Benutzerdaten-}
SMTP.Username := aUserName;
SMTP.Host := aHost;
SMTP.Password := aPassword;
{-fertig zum Versenden-}
try
SMTP.Connect;
try
SMTP.Send(EMail);
if aMailCopyTo <> '
'
then begin
EMail.Subject := '
[Kopie E-Mail an ' + aEmpfaenger+ '
] - ' + EMail.Subject;
EMail.Recipients.EMailAddresses := aAbsender;
EMail.ExtraHeaders.Clear;
SMTP.Send(EMail);
end;
aMsg := '
E-Mail an <'+aEmpfaenger+'
> erfolgreich gesendet um ' + DateTimeToStr(Now);
Result := True;
except
on E:
Exception do aMsg := '
Fehler beim Mail-Versand: ' + E.
Message;
end;
finally
SMTP.Disconnect;
end;
finally
EMail.Free;
Html.Free;
SMTP.Free;
end;
end;