Sending a mail with net/smtp through http CONNECT proxy

huangapple go评论71阅读模式
英文:

Sending a mail with net/smtp through http CONNECT proxy

问题

我的Go程序使用net/smtp库发送邮件。

client, err := smtp.Dial(addr)

当连接到SMTP服务器时,我想通过基于HTTP CONNECT的代理进行传递。

英文:

My Go program sends a mail with the net/smtp library.

		client, err := smtp.Dial(addr)

When connecting to the SMTP server I would like to pass through a HTTP CONNECT-based proxy.

答案1

得分: 1

要通过CONNECT代理发送SMTP流量,您需要使用smtp.NewClient(conn net.Conn, host string)并提供一个现有连接(net.Conn)到您的CONNECT代理。

magisterquis/connectproxy包很可能是您需要创建此连接的工具:

d, err := connectproxy.New("https://proxyserver:4433", proxy.Direct)
if nil != err{
     panic(err)
}

c, err := d.Dial("tcp", "upstream.mail.server:25")
if nil != err {
     panic(err)
}

smtpClient, err := smtp.NewClient(c, "upstream.mail.server")
if nil != err {
     panic(err)
}

英文:

To send SMTP traffic via a CONNECT proxy, you'll need to make use of smtp.NewClient(conn net.Conn, host string) with an existing connection (net.Conn) to your CONNECT proxy.

The magisterquis/connectproxy package is most likely be what you will need to create this connection:

d, err := connectproxy.New("https://proxyserver:4433", proxy.Direct)
if nil != err{
     panic(err)
}

c, err := d.Dial("tcp", "upstream.mail.server:25")
if nil != err {
     panic(err)
}

smtpClient, err := smtp.NewClient(c, "upstream.mail.server")
if nil != err {
     panic(err)
}

huangapple
  • 本文由 发表于 2021年8月16日 18:06:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/68800963.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定