C# 通过http代理发送邮件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/844835/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 03:53:17  来源:igfitidea点击:

Sending mail through http proxy

c#proxysmtpclienthttp-proxy

提问by Salar

I'm trying to send emails from a system that connects to internet through a http proxy which is set in Internet Options.

我正在尝试从通过 Internet 选项中设置的 http 代理连接到 Internet 的系统发送电子邮件。

i'm using SmtpClient.

我正在使用 SmtpClient。

Is there any way to send mails with SmtpClient through this proxy setting. Thanks

有没有办法通过此代理设置使用 SmtpClient 发送邮件。谢谢

采纳答案by bahith

I understand that you want to use the browsers default settings, i would also like an answer for that.

我知道您想使用浏览器的默认设置,我也想知道答案。

Meanwhile, you could do it manually.

同时,您可以手动完成。

    MailAddress from = new MailAddress("[email protected]");
    MailAddress to = new MailAddress("[email protected]");

    MailMessage mm = new MailMessage(from, to);
    mm.Subject = "Subject"
    mm.Body = "Body";

    SmtpClient client = new SmtpClient("proxy.mailserver.com", 8080);
    client.Credentials = new System.Net.NetworkCredential("[email protected]", "password");

    client.Send(mm);

回答by AnthonyWJones

Http Proxies control http traffic, they rarely have anything to do with SMTP at all. I've never heard of proxying SMTP before after all SMTP itself is intrinsically supports a chain of "proxies" to the destination SMTP server.

Http 代理控制 http 流量,它们与 SMTP 几乎没有任何关系。我从来没有听说过代理 SMTP,毕竟 SMTP 本身本质上支持到目标 SMTP 服务器的“代理”链。

回答by Luke Chadwick

If the only access you have to the internet is through HTTP, then pretty much the only way you'll be able to do this is by setting up a VPS (or equiv) with SSH on port 443 and using corkscrew (or putty) to tunnel ssh through. From there it is a simple matter to forward smtp traffic over your ssh tunnel.

如果您对互联网的唯一访问是通过 HTTP,那么几乎唯一能够做到这一点的方法就是在端口 443 上设置一个带有 SSH 的 VPS(或等效)并使用开瓶器(或腻子)来隧道 ssh 通过。从那里通过 ssh 隧道转发 smtp 流量是一件简单的事情。

Be aware that you may be violating the companies computing policy if you do this.

请注意,如果您这样做,您可能会违反公司的计算政策。