AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Netzwerke Delphi Outllook 365 MAPI HTML

Outllook 365 MAPI HTML

Ein Thema von haentschman · begonnen am 14. Jul 2021 · letzter Beitrag vom 20. Jul 2021
 
Benutzerbild von haentschman
haentschman

Registriert seit: 24. Okt 2006
Ort: Seifhennersdorf / Sachsen
5.436 Beiträge
 
Delphi 12 Athens
 
#7

AW: Outllook 365 MAPI HTML

  Alt 20. Jul 2021, 12:59
Moin...

Meine Lösung heißt: TOutlookApplication

In der Konfiguration kann man nun wählen welcher Client am Start ist.

Auszüge:
Delphi-Quellcode:
function TToolsMail.SendMailClient: Boolean;
var
  FunctionResult: Boolean;

  function SendMAPI: Boolean;

  {$REGION 'Inline'}
    procedure FillMailRecipents;
    var
      I: Integer;
      RecipientItem: TCollectionItem;
    begin
    {$REGION 'Code'}
      FMailStandardClient.Recipients.Clear;
      for I := 0 to FMailMessage.ToList.Count - 1 do
      begin
        RecipientItem := FMailStandardClient.Recipients.Add;
        TRecipientItem(RecipientItem).Address := FMailMessage.ToList.Items[I].Email;
      end;
    {$ENDREGION}
    end;

    procedure FillMailAttachments;
    var
      I: Integer;
    begin
    {$REGION 'Code'}
      FMailStandardClient.Attachments.Clear;
      for I := 0 to FAttachments.Count - 1 do
      begin
        FMailStandardClient.Attachments.Add(FAttachments[I]);
      end;
    {$ENDREGION}
    end;

    procedure FillMailBody;
    begin
    {$REGION 'Code'}
      FMailStandardClient.Subject := FMailMessage.Subject;
      FMailStandardClient.Text := FMailMessage.Html.Strings;
    {$ENDREGION}
    end;
  {$ENDREGION}

  begin
    FillMailBody;
    FillMailRecipents;
    FillMailAttachments;

    Result := FMailStandardClient.Execute;
  end;

  function SendOutlook: Boolean;
  var
    Outlook: TOutlookApplication;
    Mail: OleVariant;

  {$REGION 'Inline'}
    procedure FillMailRecipents;
    var
      List: TStringList;
    begin
    {$REGION 'Code'}
      List := TStringList.Create;
      try
        List.Delimiter := ';';
        FMailMessage.ToList.GetEmailList(List);
        Mail.To := List.DelimitedText;
      finally
        List.Free;
      end;
    {$ENDREGION}
    end;

    procedure FillMailAttachments;
    var
      I: Integer;
    begin
    {$REGION 'Code'}
      for I := 0 to FAttachments.Count - 1 do
      begin
        Mail.Attachments.Add(FAttachments[I]);
      end;
    {$ENDREGION}
    end;

    procedure FillMailBody;
    begin
    {$REGION 'Code'}
      Mail.BodyFormat := olFormatHTML;
      Mail.Subject := FMailMessage.Subject;
      Mail.GetInspector;
      Mail.HTMLBody := OleVariant(FMailMessage.Html.Strings.Text) + Mail.HTMLBody;
    {$ENDREGION}
    end;
  {$ENDREGION}

  begin
    Result := True;
    Outlook:= TOutlookApplication.Create(nil);
    try
      Mail := Outlook.CreateItem(olMailItem);

      FillMailBody;
      FillMailRecipents;
      FillMailAttachments;

      try
        Mail.Display;
      except
        Result := False;
      end;
    finally
      Outlook.Free;
    end;
  end;

begin
  Result := True;
  try
    FunctionResult := False;

    FMail.Open;
    try
      CreateMailMessage;

      case FPreferences.PreferencesMail.ClientType of
        cltMAPI:
        begin
          FunctionResult := SendMAPI;
        end;
        cltOutlook:
        begin
          FunctionResult := SendOutlook;
        end;
      end;

      if FunctionResult then
      begin
        WriteMailDB;
        if Assigned(FOnMailSend) then
        begin
          FOnMailSend(Self, FMailMessage.ToList.EmailAddresses, FMailMessage.Subject);
        end;
      end;
    finally
      FMail.Close;
    end;
  except
    on E: System.SysUtils.Exception do
    begin
      if Assigned(FOnMailError) then
      begin
        FOnMailError(Self, FReceipients, FMailMessage.Subject, E.Message);
      end;
      Result := False;
    end;
  end;
end;
  Mit Zitat antworten Zitat
 

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 22:23 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz