xhit / go-simple-mail

Golang package for send email. Support keep alive connection, TLS and SSL. Easy for bulk SMTP.
MIT License
650 stars 102 forks source link

Why is it not possible to use proxy? #79

Closed awiz911 closed 1 year ago

awiz911 commented 1 year ago

I saw question and comment about proxy in closed issue.

However it's not a network issue.

With "net/smtp" and "golang.org/x/net/proxy" we can easily create smtpClient through proxy:

Dial, err := proxy.SOCKS5("tcp", "some-proxy-address", nil, proxy.Direct)
if err != nil {
    return nil, errors.Wrap(err, "Create SOCKS5")
}

dialer, err = Dial.Dial("tcp", "host-addr")
if err != nil {
    return nil, errors.Wrap(err, "Dial")
}

conf := &tls.Config{ServerName: "host-addr-without-port"}
tlsdialer := tls.Client(dialer, conf)

client, err := smtp.NewClient(tlsdialer, "host-addr")
if err != nil {
    panic(err)
}

auth := smtp.PlainAuth("", user, pass, "host-addr")
if err = client.Auth(auth); err != nil {
    panic(err)
}

And would be awesome if smth like this would be possible in this package. Cuz it's quite convient for sending mail. Or if it's too much trouble, then why was smtpClient made not exportable in the first place. It has couple slight differences with net's smtp.Client type: there's a instead of auth and Text made exportable. If instead of creating separate type net's smtp.Client was used then we would have proxy as in code above. Even if there's a different type, then methods to change connections would work too.

Or add couple params to SMTPServer type for proxy and on connect if there are filled in use them for connection. So many ways to do it. Wander why it wasn't done in the first place. (

xhit commented 1 year ago

(sorry for my bad English)

Hi Aleksey, thanks for your share your thoughs.

In that moment, 2021, I only had this package for some internal uses in the company, so any proposed change that wasn't required was rejected and I apologize for that.

At this moment, this package is open to any change that will be useful for anyone. That's why I create the v3 branch to allow contributors the changes that will be a breaking change like make a exportable smtpClient, func name changes, etc...

Currently I'm connected to check it every night, but I paused the development by me to concentrate in other projects. So, if you have a change that is a breaking change, use v3 branch, otherwise, the master branch as the destination branch for your PR.

I can make this happens, but I will not compromise for a short time.

I will left this issue opened and pinned, although I don´t receive PR, is in my TODO list.

Thanks.

awiz911 commented 1 year ago

Your english is fine. )

I might just do that actually. Will get payed for it too. ))) Without this package would have to pretty much make my own from scratch for project I'm working on. So this seems like a faster way to finish. )))

xhit commented 1 year ago

Hi @awiz911, now you can use a your custom connection https://github.com/xhit/go-simple-mail#send-with-custom-connection

Sorry for delay, thanks for the motivation 🚀

awiz911 commented 1 year ago

@xhit I'm the one who should be sorry. ( Got caught up with work projects and code-contests and didn't find time to add solution myself. ( Thanks for great lib and great work.