I am using "net/mail" and "net/smtp" to create an email client in Go, but it fails when it's behind the proxy.
I had the same issue for http client but it got resolved using &http.Transport{Proxy: http.ProxyFromEnvironment}
couldn't find a similar fix for SMTP
The below code works on my machine, which is behind the co-corporate proxy. but if I run the same code on a VM which is not behind any proxy, It works.
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")
}