Enough-Software / enough_mail

IMAP, POP3 and SMTP clients for Dart developers. Contains both low level as well as a high level API.
Mozilla Public License 2.0
100 stars 56 forks source link

How to setup and use the http/https/socks5 proxy to connect IMAP/POP3 server? #169

Open gzlock opened 2 years ago

gzlock commented 2 years ago

I checked the enough_mail document and no such content.

robert-virkus commented 2 years ago

What's your use-case? If you have set up a proxy on your system, this should be transparent to any network app as far as I understand....

gzlock commented 2 years ago

What's your use-case? If you have set up a proxy on your system, this should be transparent to any network app as far as I understand....

I'm chinese, my browser can open google.com when I use a proxy application image

But I follow the example(High Level API) and try to connect google server(gmail account), the console show connect dns.google.com timeout.

I tried it on the flutter windows desktop mode.

BTW, I used the ThunderBird mail application, I can’t login to gmail when I use it by default, but it provided the network proxy settings, and I set the proxy to 127.0.0.1:7890, it can login gmail.

robert-virkus commented 2 years ago

This seems to be an problem for Dart and Flutter, compare for example

I have found this GPL-licensed library that allows to connect via Socks5: https://github.com/v0l/socks5

One idea could be to abstract sockets in enough_mail and allow clients to specify a SocketFactory or similar.

Thoughts? Ideas? Suggestions?

gzlock commented 2 years ago

It can be done like the dio package, allowing proxy settings https://pub.dev/packages/dio#using-proxy

import 'package:dio/dio.dart';
import 'package:dio/adapter.dart';
...
(dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (client) {
  // config the http client
  client.findProxy = (uri) {
    //proxy all request to localhost:8888
    return 'PROXY localhost:8888';
  };
  // you can also create a new HttpClient to dio
  // return HttpClient();
};
robert-virkus commented 2 years ago

Dio just exposes the dart:io HttpClient's findProxy(Uri) callback. While I agree that this would be a nice API, I have no idea how to implement this. I cannot integrate with the above mentioned socks5 project, as that is licensed under the GPL-copy-left license and this does not mix with this project's MPL license. So either this would need to be re-implemented or solved differently.

The underlying question is:

hsy159 commented 12 months ago

I have a same question.. (maybe it's so late..? lol) How can i use socks proxy?

lwdsw commented 8 months ago

Has this problem been solved?