Hi,
I am trying to figure out how to connect to office 365 through a proxy server. My application is working well if I connect without a proxy. But now the requirement changed and direct connection to internet is not allowed and I have to use a proxy. I can connect to office 365 from the production machine through proxy using a browser. So the connection setup is good. Now I need to change my application to use a proxy. So I looked around and found that I have to use TIdIOHandlerStack and IdConnectThroughHttpProxy1 to achieve it. But the help document is not that great. So looking for suggestions/help.
My code looks like this.
type
TForm1 = class(TForm)
Button1: TButton;
IdIMAP: TIdIMAP4;
IdConnectThroughHttpProxy1: TIdConnectThroughHttpProxy;
IdIOHandlerStack1: TIdIOHandlerStack;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
IdIMAP.Username := 'test@test.com'; // outlook user name
IdIMAP.Password := 'xxxxx'; // outlook user password
IdIMAP.Port := 993; // outlook server port
IdIMAP.Host := 'outlook.office365.com'; // outlook server
IdIMAP.AuthType := iatUserPass;
IdConnectThroughHttpProxy1.Host := 'x.x.x.x'; // Proxy server
IdConnectThroughHttpProxy1.Port := 1234; // Proxy server port
IdIOHandlerStack1.TransparentProxy := IdConnectThroughHttpProxy1;
IdIMAP.IOHandler := IdIOHandlerStack1;
try
Memo1.Lines.Clear;
Memo1.Lines.Add('Trying to connect to server...');
if not IdIMAP.Connected then
begin
if IdIMAP.Connect(false) then
Memo1.Lines.Add('Connected to server')
else
Memo1.Lines.Add('NOT Connected to server')
end;
Memo1.Lines.Add('Trying to login to server...');
if not(IdIMAP.ConnectionState in [csAuthenticated, csSelected]) then
IdIMAP.Login;
Memo1.Lines.Add('Logged in to server');
except
on E: Exception do
begin
Memo1.Lines.Add('Error while connecting: ' + E.Message);
end;
end;
end;
When I try this, I get "Error while connecting: 403 forbidden error"
Thanks for your time,
Kind regards,
Soji.