@@ -12,11 +12,13 @@ import (
12
12
"io"
13
13
"net"
14
14
"net/textproto"
15
+ "net/url"
15
16
"strconv"
16
17
"strings"
17
18
"time"
18
19
19
20
"github.com/emersion/go-sasl"
21
+ "github.com/txthinking/socks5"
20
22
)
21
23
22
24
// A Client represents a client connection to an SMTP server.
@@ -61,6 +63,29 @@ func Dial(addr string) (*Client, error) {
61
63
return NewClient (conn , host )
62
64
}
63
65
66
+ // DialWithSocks5 returns a new Client connected to an SMTP server via socks5 proxy at addr.
67
+ // The addr must include a port, as in "mail.example.com:smtp".
68
+ // The socks5URI must include username and password, as in "user:[email protected] :1080"
69
+ func DialWithSocks5 (addr string , socks5URI string ) (* Client , error ) {
70
+ u , err := url .Parse (socks5URI )
71
+ if err != nil {
72
+ return nil , err
73
+ }
74
+ username := u .User .Username ()
75
+ password , _ := u .User .Password ()
76
+ socksClient , err := socks5 .NewClient (u .Host , username , password , 60 , 60 )
77
+ if err != nil {
78
+ return nil , err
79
+ }
80
+
81
+ conn , err := socksClient .Dial ("tcp" , addr )
82
+ if err != nil {
83
+ return nil , err
84
+ }
85
+ host , _ , _ := net .SplitHostPort (addr )
86
+ return NewClient (conn , host )
87
+ }
88
+
64
89
// DialTLS returns a new Client connected to an SMTP server via TLS at addr.
65
90
// The addr must include a port, as in "mail.example.com:smtps".
66
91
//
0 commit comments