How to make Apple Mail.app to use SOCKS proxy configured by a PAC file

For some reasons, I have to use a SOCKS proxy to access Gmail, otherwise, the connection will be blocked.

I tried the global SOCKS agent, and the Mail.app worked fine. Nevertheless, when I turned to use a PAC file to configure system agent automatically, the Mail.app wasn't able to access Gmail.

My questions:

  1. Is it possible to set proxy in Mail.app? That is, Mail.app passes its web traffic to the SOCKS proxy while other apps won't be influenced.
  2. If the answer to the first question is NO, then how to modify my PAC file to make Mail.app possible to access Gmail?

Any clues or suggestions would be appreciated.


More info:

OS version: OS X 10.9.5

Mail.app version: 7.3 (1878.6)

The PAC file:

var domains = {
  "l.google.com": 1,
  "gmail-imap.l.google.com": 1,
  "googlepages.com": 1,  
  "googlesile.com": 1, 
  "google.co.jp": 1, 
  "gaeproxy.googlecode.com": 1, 
  "sshtunnel.googlecode.com": 1, 
  "googleusercontent.com": 1, 
  "goagent.googlecode.com": 1, 
  "google.com": 1, 
  "googlevideo.com": 1, 
  "google.com.hk": 1, 
  "tuite.googlecode.com": 1, 
  "gfwinterceptor.googlecode.com": 1, 
  "gtap.googlecode.com": 1, 
  "googleapis.com": 1
};

var proxy = "SOCKS5 127.0.0.1:1080; SOCKS 127.0.0.1:1080; DIRECT;";

var direct = 'DIRECT;';

function FindProxyForURL(url, host) {
    var lastPos;
    do {
        if (domains.hasOwnProperty(host)) {
            return proxy;
        }
        lastPos = host.indexOf('.') + 1;
        host = host.slice(lastPos);
    } while (lastPos >= 1);
    return direct;
}

Solution 1:

Try go to Network Preferences, select the network you want to set, and go to Advanced -> Proxies. Then, set both Automatic Proxy Configuration and SOCKS proxy. It works for me.

FYI, if you're using Shadowsocks the PAC would probably be http://127.0.0.1:8090/proxy.pac.

Solution 2:

I know this thread is old, but I had the same problem thanks to the great firewall. I didn't want to route ALL of my traffic through my proxy, so setting this in network preferences was not an option.

I thought the problem was because of the Mail app on mac, but actually it was just access to the IMAP and SMTP gmail servers.

For whatever reason, the main GFW list doesn't include these. All you need to do is add these two lines to your PAC file:

||imap.gmail.com^ ||smtp.gmail.com^

As soon as I added those, the mail app was working with gmail. I hope this works for you!