1

Is it possible to use the Gmail REST API to retrieve emails (with the complete body) when you are behind a corporate HTTP proxy?

If so, can someone please provide a Java example to atleast make the connection using the proxy, so I can figure out the rest by myself?

Ok, so I see that my question has been marked as duplicate, and am given the following link: How do I make HttpURLConnection use a proxy?

This does not help me at all. I am referring to the Gmail REST API (https://developers.google.com/gmail/api/quickstart/quickstart-java). Have a look at the quickstart link I sent, it doesnt use HttpURLConnection.

It would have been courteous and productive if someone asked me before marking my question as duplicate thereby multiplying my work.

So again I ask, how can I make a connection to the Gmail REST API if I am behind a corporate proxy? In order to avoid confusion, please answer with respect to the example provided in the quickstart link I sent above.

Community
  • 1
  • 1
jsmith
  • 89
  • 1
  • 15
  • 1
    It looks like that question does answer the question you asked. Can Gmail REST be accessed behind a firewall. Yes. [This answer](http://stackoverflow.com/a/1433296/442351) says how to connect to a REST interface. – BanksySan May 04 '15 at 02:54
  • Try setting the system properties as described [here](http://i4t.org/2007/05/04/java-http-proxy-settings/). There is a good chance HttpUrlConnection is used behing the scenes or that the Google APIs honor these settings – Bruno Grieder May 04 '15 at 04:52

1 Answers1

0

I have been searching for the same from quite a long time ago and finally I am able to inject the corporate proxy and make successfully connection to Gmail REST API.

Here you go - In order to get this done , you need to add below code snippet in https://developers.google.com/gmail/api/quickstart/quickstart-java

static HttpTransport newProxyTransport() throws GeneralSecurityException, IOException { NetHttpTransport.Builder builder = new NetHttpTransport.Builder(); builder.trustCertificates(GoogleUtils.getCertificateTrustStore()); builder.setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("10.0.0.1", 8080))); return builder.build(); }

call the newProxyTransport() in quickStart.java as below :

static { try { HTTP_TRANSPORT = newProxyTransport(); DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR); } catch (Throwable t) { t.printStackTrace(); System.exit(1); } }

Hope this helps :-)

bsoni
  • 1