Link to home
Start Free TrialLog in
Avatar of formi
formiFlag for Switzerland

asked on

send email with outlook (from delphi-application). Send-Window does not open.

Hi

using Delphi 10.1 and outlook 365.
There are only some clients where I have the problem: I can not send EMail from my application. On my computer and most other clients-computers it works. But there are computers, where only outlook is startet but no send-window is opend. Retring a second time, outlook is startet also a second time...
  OutlookApplication1.Connect;
  try
    MailItem1 := OutlookApplication1.CreateItem(olMailItem)  as _MailItem;
    while toAdress <> '' do
    begin
      if Pos(';',toAdress) > 0 then
      begin
        MailItem1.Recipients.Add(Copy(toAdress,1,Pos(';',toAdress)-1));
        Delete(toAdress,1,Pos(';',toAdress));
      end
      else
      begin
        MailItem1.Recipients.Add(toAdress);
        toAdress := '';
      end;
    end;
    MailItem1.CC := ToCC;
    MailItem1.BCC := ToBCC;
    MailItem1.Subject := Subject;
    if EMailOutlookAbsender = '' then  //local definitions?
    begin
      if Pos('@',getOptionMandantS('EMail_Absender','')) > 0 then
        MailItem1.SendUsingAccount := OutlookApplication1.Session.Accounts.Item(getOptionMandantS('EMail_Absender',''));
    end
    else MailItem1.SendUsingAccount := OutlookApplication1.Session.Accounts.Item(EMailOutlookAbsender); //globale Einstellung
    Mailitem1.BodyFormat := olFormatHTML;
    //the default signature is added
    ObjectInspector := Mailitem1.getinspector;

    if ObjectInspector.EditorType = olEditorWord then
    begin
      WordEditor := ObjectInspector.WordEditor;
      WordEditor.Characters.item(1).InsertBefore(Htmltext);
    end
    else
    begin
      Mailitem1.HtmlBody := StringReplace(Mailitem1.HtmlBody,'<body>','<body>'+Htmltext,[rfReplaceAll,rfIgnoreCase]);
    end;
    if AttachedFileNames <> nil then
    begin
      for i := 0 to AttachedFileNames.Count - 1 do
        MailItem1.Attachments.Add(AttachedFileNames[i], EmptyParam, EmptyParam, EmptyParam);
    end;
    MailItem1.Display(true);

Open in new window

Any idea where the problem is?
Thanks, Peter
Avatar of Lukasz Zielinski
Lukasz Zielinski
Flag of Poland image

Well if it works on some PCs but doesn't on others there are two options:
- it does not depend on your code but Outlook version and/or settings
- your code fails somewhere between OutlookApplication1.Connect; and MailItem1.Display(true);

Just looking at your code there is nothing suspicious, but the problem might be here:
OutlookApplication1.Session.Accounts.Item() <- maybe there are no items?
or maybe there is a problem with using word editor.

But it's impossible to tell just by looking at your code.
So if there is PC on which you can reproduce it every time - just make special build or little test app that would out put debug info to make sure your code reaches MailItem1.Display(true); point.

To save time I would suggest putting debug info after each line of your code

ziolko.
Avatar of formi

ASKER

Now I displayed the errors and tested with Office home and Business 2016

1. (translated from german): "no pointer can be assigned to a executed object that is registered with OLE outlook.application.16" . If I search in the registry I find such an entry (see images). This occurs if outlook is not execueted. If outlook runs I get the error "Interface not supported"
2. in the taskmanager, the process outlook.exe is visible but when I want to check if outlook is running with "GetProcessList" this process isn't in the list.
User generated imageUser generated image
do you know which line of your code generates this error?
Avatar of formi

ASKER

it's this one: OutlookApplication1.Connect
ASKER CERTIFIED SOLUTION
Avatar of Lukasz Zielinski
Lukasz Zielinski
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of formi

ASKER

Hi Lukasz, thanks a lot for your help. Late binding is the solution. The only thing is that outlook has to be executed and since I can not detect the process  with "GetProcessList". But this is another subject and if I don't find the solution I'll start another topic.