Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IdMessageClient problem
#4
(10-19-2021, 12:05 AM)Robert Gilland Wrote: This works for me:

Why are you adding the attachments to both the TIdMessage and a TObjectStringsList?

In any case, you might consider using TIdMessageBuilderHtml to simplify the logic of populating the TIdMessage body, eg:

Code:
idmsg := TIdMssage.Create;
try
  idmsg.Date := Now;
  idmsg.FromList.EMailAddresses := FEmailReply;
  idmsg.Subject := SubJect;
  idmsg.Recipients.EMailAddresses := ReceiveAddr;

  idMsgBldr := TIdMessageBuilderHtml.Create;
  try
    idMsgBldr.Html.Assign(slInfo);
    for j := 0 to slFiles.Count-1 do begin
      idMsgBldr.Attachments.Add(slFiles[j]);
    end;
    if Assigned(psInsideFiles) then begin
      for j := 0 to psInsideFiles.Count-1 do
        idMsgBldr.HtmlFiles.Add(psInsideFiles[j], TStringObj(psInsideFiles.Objects[j]).TheString);
    end;
    idMsg := idMsgBldr.FillMessage(idMsg);
  finally
    idMsgBldr.Free;
  end;

  // use idMsg as needed...
finally
  idMsg.Free;
end;

Alternatively:

Code:
idmsg := nil;
try
  idMsgBldr := TIdMessageBuilderHtml.Create;
  try
    idMsgBldr.Html.Assign(slInfo);
    for j := 0 to slFiles.Count-1 do begin
      idMsgBldr.Attachments.Add(slFiles[j]);
    end;
    if Assigned(psInsideFiles) then begin
      for j := 0 to psInsideFiles.Count-1 do
        idMsgBldr.HtmlFiles.Add(psInsideFiles[j], TStringObj(psInsideFiles.Objects[j]).TheString);
    end;
    idMsg := idMsgBldr.NewMessage;
  finally
    idMsgBldr.Free;
  end;

  idmsg.Date := Now;
  idmsg.FromList.EMailAddresses := FEmailReply;
  idmsg.Subject := SubJect;
  idmsg.Recipients.EMailAddresses := ReceiveAddr;
  // use idMsg as needed...

finally
  idMsg.Free;
end;

Reply


Messages In This Thread
IdMessageClient problem - by scampsmith - 10-18-2021, 07:36 PM
RE: IdMessageClient problem - by rlebeau - 10-19-2021, 12:01 AM
RE: IdMessageClient problem - by Robert Gilland - 10-19-2021, 12:05 AM
RE: IdMessageClient problem - by rlebeau - 10-19-2021, 12:44 AM
RE: IdMessageClient problem - by scampsmith - 10-19-2021, 01:59 PM
RE: IdMessageClient problem - by rlebeau - 10-19-2021, 05:52 PM
RE: IdMessageClient problem - by scampsmith - 10-19-2021, 07:22 PM
RE: IdMessageClient problem - by rlebeau - 10-19-2021, 10:50 PM
RE: IdMessageClient problem - by scampsmith - 10-20-2021, 12:21 PM
RE: IdMessageClient problem - by rlebeau - 10-20-2021, 06:02 PM
RE: IdMessageClient problem - by scampsmith - 10-20-2021, 07:20 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)