Attach file using Webbrowser Delphi

Asked

Viewed 405 times

2

I am developing a tool to automate the sending of emails from the company, I wanted to know how to automatically load an attachment as in this screenshot

inserir a descrição da imagem aqui

Remember that I need to make use of Twebbrowser .

I need him to do this, by clicking on the button, automatically add the attachment ! inserir a descrição da imagem aqui

  • Can’t do what you want, because that property is read-only, how can you see here, see the item name, this is due to security issues.

  • What you can do is send the file(s) separately using the IdHTTP.

  • zekk, can you give me an example of how to do this?

1 answer

1

It is not possible to change this field because it is read-only due to security issues.

What you can do is send the file separately using the components of Indy, the TIdMultipartFormDataStream and TIdHTTP.

Uses
  IdMultipartFormData, IdHTTP,
  IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient;

//....

procedure EnviarArquivo(const URL, Campo, Arquivo: string);
var
  IdHttp: TIdHTTP;
  Parametros: TIdMultipartFormDataStream;
  SS: TStringStream;
begin
  IdHttp := TIdHTTP.Create(nil);
  SS := TStringStream.Create();
  try
    Parametros := TIdMultipartFormDataStream.Create;
    try
      Parametros.AddFile(Campo, Arquivo);
      try
        IdHttp.Post(URL, Parametros, SS);
        ShowMessage('Status: ' + IntToStr(IdHttp.ResponseCode));
      except
        on E: Exception do
          ShowMessage('Post Error: ' + E.Message);
      end;
    Memo1.Text := SS.DataString;
    finally
      Parametros.Free;
    end;
  finally
    IdHttp.Free;
    SS.Free;
  end;
end;

Use like this:

procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
  EnviarArquivo('<URL>', 'attachmentElement', '<CaminhoDoArquivo>');
end;
  • Only one question.. the URL I pass only the main one, or I need to parse the GET/POST to have the exact URL.. ?

  • If I’m not mistaken, you need to pass the data as Parametros in the IdHttp.Post

  • @Ronald Functioned?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.