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")










share|improve this question



















  • 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















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")










share|improve this question



















  • 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













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")










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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













  • 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


















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo