Use SMTP / Email Client behind proxy in GO
up vote
-2
down vote
favorite
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.TransportProxy: 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")
email go proxy smtpclient
|
show 3 more comments
up vote
-2
down vote
favorite
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.TransportProxy: 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")
email go proxy smtpclient
2
There's no such thing as an SMTP proxy, per se, except to the extent that every SMTP server can serve as a proxy. Which exact "system proxy settings" were you thinking of using?
– Flimzy
Nov 10 at 10:08
See github.com/Supme/directEmail/blob/master/send.go for some code that diverts SMTP through a socks proxy
– Vorsprung
Nov 10 at 11:31
i am not trying to make a proxy server. the vm on where my code runs is behind a proxy, so i need a way by which my email client will make calls using proxy
– Chinmay Samant
Nov 10 at 12:44
@ChinmaySamant: This isn't a coding problem. You need to allow access to an SMTP server somehow, from within your VM. A common way to do this is with a 'smarthost' (the SMTP term most similar to a 'proxy'), but this is entirely a networking/server issue, nothing to do with coding.
– Flimzy
Nov 10 at 15:34
i fail to understand how it's not a coding problem.!! for http client in GO to work behind proxy i had to use&http.TransportProxy: http.ProxyFromEnvironment
so in similar way, i am asking what should i use for smtp clinet in GO to make it work behind proxy?
– Chinmay Samant
Nov 11 at 5:45
|
show 3 more comments
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
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.TransportProxy: 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")
email go proxy smtpclient
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.TransportProxy: 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")
email go proxy smtpclient
email go proxy smtpclient
edited Nov 14 at 6:43
asked Nov 10 at 7:14
Chinmay Samant
80110
80110
2
There's no such thing as an SMTP proxy, per se, except to the extent that every SMTP server can serve as a proxy. Which exact "system proxy settings" were you thinking of using?
– Flimzy
Nov 10 at 10:08
See github.com/Supme/directEmail/blob/master/send.go for some code that diverts SMTP through a socks proxy
– Vorsprung
Nov 10 at 11:31
i am not trying to make a proxy server. the vm on where my code runs is behind a proxy, so i need a way by which my email client will make calls using proxy
– Chinmay Samant
Nov 10 at 12:44
@ChinmaySamant: This isn't a coding problem. You need to allow access to an SMTP server somehow, from within your VM. A common way to do this is with a 'smarthost' (the SMTP term most similar to a 'proxy'), but this is entirely a networking/server issue, nothing to do with coding.
– Flimzy
Nov 10 at 15:34
i fail to understand how it's not a coding problem.!! for http client in GO to work behind proxy i had to use&http.TransportProxy: http.ProxyFromEnvironment
so in similar way, i am asking what should i use for smtp clinet in GO to make it work behind proxy?
– Chinmay Samant
Nov 11 at 5:45
|
show 3 more comments
2
There's no such thing as an SMTP proxy, per se, except to the extent that every SMTP server can serve as a proxy. Which exact "system proxy settings" were you thinking of using?
– Flimzy
Nov 10 at 10:08
See github.com/Supme/directEmail/blob/master/send.go for some code that diverts SMTP through a socks proxy
– Vorsprung
Nov 10 at 11:31
i am not trying to make a proxy server. the vm on where my code runs is behind a proxy, so i need a way by which my email client will make calls using proxy
– Chinmay Samant
Nov 10 at 12:44
@ChinmaySamant: This isn't a coding problem. You need to allow access to an SMTP server somehow, from within your VM. A common way to do this is with a 'smarthost' (the SMTP term most similar to a 'proxy'), but this is entirely a networking/server issue, nothing to do with coding.
– Flimzy
Nov 10 at 15:34
i fail to understand how it's not a coding problem.!! for http client in GO to work behind proxy i had to use&http.TransportProxy: http.ProxyFromEnvironment
so in similar way, i am asking what should i use for smtp clinet in GO to make it work behind proxy?
– Chinmay Samant
Nov 11 at 5:45
2
2
There's no such thing as an SMTP proxy, per se, except to the extent that every SMTP server can serve as a proxy. Which exact "system proxy settings" were you thinking of using?
– Flimzy
Nov 10 at 10:08
There's no such thing as an SMTP proxy, per se, except to the extent that every SMTP server can serve as a proxy. Which exact "system proxy settings" were you thinking of using?
– Flimzy
Nov 10 at 10:08
See github.com/Supme/directEmail/blob/master/send.go for some code that diverts SMTP through a socks proxy
– Vorsprung
Nov 10 at 11:31
See github.com/Supme/directEmail/blob/master/send.go for some code that diverts SMTP through a socks proxy
– Vorsprung
Nov 10 at 11:31
i am not trying to make a proxy server. the vm on where my code runs is behind a proxy, so i need a way by which my email client will make calls using proxy
– Chinmay Samant
Nov 10 at 12:44
i am not trying to make a proxy server. the vm on where my code runs is behind a proxy, so i need a way by which my email client will make calls using proxy
– Chinmay Samant
Nov 10 at 12:44
@ChinmaySamant: This isn't a coding problem. You need to allow access to an SMTP server somehow, from within your VM. A common way to do this is with a 'smarthost' (the SMTP term most similar to a 'proxy'), but this is entirely a networking/server issue, nothing to do with coding.
– Flimzy
Nov 10 at 15:34
@ChinmaySamant: This isn't a coding problem. You need to allow access to an SMTP server somehow, from within your VM. A common way to do this is with a 'smarthost' (the SMTP term most similar to a 'proxy'), but this is entirely a networking/server issue, nothing to do with coding.
– Flimzy
Nov 10 at 15:34
i fail to understand how it's not a coding problem.!! for http client in GO to work behind proxy i had to use
&http.TransportProxy: http.ProxyFromEnvironment
so in similar way, i am asking what should i use for smtp clinet in GO to make it work behind proxy?– Chinmay Samant
Nov 11 at 5:45
i fail to understand how it's not a coding problem.!! for http client in GO to work behind proxy i had to use
&http.TransportProxy: http.ProxyFromEnvironment
so in similar way, i am asking what should i use for smtp clinet in GO to make it work behind proxy?– Chinmay Samant
Nov 11 at 5:45
|
show 3 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53236820%2fuse-smtp-email-client-behind-proxy-in-go%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
There's no such thing as an SMTP proxy, per se, except to the extent that every SMTP server can serve as a proxy. Which exact "system proxy settings" were you thinking of using?
– Flimzy
Nov 10 at 10:08
See github.com/Supme/directEmail/blob/master/send.go for some code that diverts SMTP through a socks proxy
– Vorsprung
Nov 10 at 11:31
i am not trying to make a proxy server. the vm on where my code runs is behind a proxy, so i need a way by which my email client will make calls using proxy
– Chinmay Samant
Nov 10 at 12:44
@ChinmaySamant: This isn't a coding problem. You need to allow access to an SMTP server somehow, from within your VM. A common way to do this is with a 'smarthost' (the SMTP term most similar to a 'proxy'), but this is entirely a networking/server issue, nothing to do with coding.
– Flimzy
Nov 10 at 15:34
i fail to understand how it's not a coding problem.!! for http client in GO to work behind proxy i had to use
&http.TransportProxy: http.ProxyFromEnvironment
so in similar way, i am asking what should i use for smtp clinet in GO to make it work behind proxy?– Chinmay Samant
Nov 11 at 5:45