gpt4 book ai didi

email - 在 GO 中使用代理后面的 SMTP/电子邮件客户端

转载 作者:数据小太阳 更新时间:2023-10-29 03:41:59 24 4
gpt4 key购买 nike

我正在使用“net/mail”和“net/smtp”在 Go 中创建电子邮件客户端,但在代理后面时失败。

我对 http 客户端也有同样的问题,但使用 &http.Transport{Proxy: http.ProxyFromEnvironment} 解决了这个问题,找不到 SMTP 的类似修复

下面的代码在我的机器上运行,它位于联合企业代理的后面。但是如果我在不在任何代理后面的虚拟机上运行相同的代码,它就可以工作。

package main

import (
"fmt"
"net/smtp"
)

func main() {
fmt.Println("email sending")
// Set up authentication information.
auth := smtp.PlainAuth(
"",
"ma****017@gmail.com",
"A***a",
"smtp.gmail.com",
)
// Connect to the server, authenticate, set the sender and recipient,
// and send the email all in one step.
err := smtp.SendMail(
"smtp.gmail.com:587",
auth,
"ma***17@gmail.com",
[]string{"chi****11@gmail.com"},
[]byte("This is the email body."),
)
if err != nil {
panic(err)
}
fmt.Println("email sent")
}

最佳答案

@Flimzy 我是网络方面的新手,是的!现在我明白这不是编码问题,而是网络问题。

对我有用的解决方案是我在代理计算机上配置 postfix 以将其中继到 Gmail SMTP 服务器。 (确保你的代理机器可以访问你需要的 SMTP 服务器)
代理机器ip需要在SMTP golang客户端设置为SMTP主机。

关于email - 在 GO 中使用代理后面的 SMTP/电子邮件客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53236820/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com