Attach file using WebBrowser Delphi

1

I'm developing a tool to automate the sending of emails from the company, I wanted to know how to automatically load an attachment like this screenshot

RememberthatIneedtouseTWebBrowser.

Ineedittodothis,byclickingthebutton,itautomaticallyaddstheattachment!

    
asked by anonymous 14.08.2016 / 08:36

1 answer

0

You can not change this field because it is read-only because of security issues .

What you can do is submit the file separately using the Indy components, 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 this:

procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
  EnviarArquivo('<URL>', 'attachmentElement', '<CaminhoDoArquivo>');
end;
    
14.08.2016 / 22:14