代理阻止我的程序连接到互联网
所以我编写了这个程序来向我的一群朋友发送短信。 在家里用得很好,但在工作中使用却不起作用。我收到错误消息“发送邮件失败”。
我们在工作中使用拦截代理。我虽然/希望一切都会顺利,但显然不行。
那么我需要做什么,我从未编程过通过代理连接/发送流量。
我使用 C# 和 SmtpClient 类来发送消息。 这是一个小片段。
SmtpClient client = new SmtpClient(emailType.Address, emailType.Port);
client.Credentials = new System.Net.NetworkCredential(tbxAccountUser.Text, tbxUserPassword.Text);
client.Send(message);
我与我们的 IT 部门交谈,我拥有他们正在使用的 IP,但我不确定我需要什么。我什至不确定要使用哪个类...
我尝试过:
WebRequest myWebRequest = WebRequest.Create("http:// /www.google.com"); WebProxy myProxy = new WebProxy(); // 获取默认浏览器的代理属性
myProxy = (WebProxy)myWebRequest.Proxy;
Uri newUri = new Uri("http://"+ ip +":8080");
// Associate the new Uri object to the myProxy object.
myProxy.Address = newUri;
// Create a NetworkCredential object and is assign to the Credentials property of the Proxy object.
myProxy.Credentials = new NetworkCredential(userName, passWd);
myWebRequest.Proxy = myProxy;
我不确定是否可以将其设置为我的 SmtpClient 客户端?
谢谢
So I wrote this program to send a group of my friends a text message.
It works fine at home when I try to use it at work it doesn't work. I get an error message "Failure Sending Mail".
We are using a intercepting proxy at work. I though/hoped that everything would just work, clearly not.
So what do I need to do, I've never programmed to connect/send traffic through a proxy.
I'm using C# and the SmtpClient class to send the message.
Here's a little snippet.
SmtpClient client = new SmtpClient(emailType.Address, emailType.Port);
client.Credentials = new System.Net.NetworkCredential(tbxAccountUser.Text, tbxUserPassword.Text);
client.Send(message);
I talked to our IT department and I have the IP that they are using but I wasn't sure what I need. I'm not even sure what class to use...
I tried this:
WebRequest myWebRequest = WebRequest.Create("http://www.google.com");
WebProxy myProxy = new WebProxy();
// Obtain the Proxy Prperty of the Default browser.
myProxy = (WebProxy)myWebRequest.Proxy;
Uri newUri = new Uri("http://"+ ip +":8080");
// Associate the new Uri object to the myProxy object.
myProxy.Address = newUri;
// Create a NetworkCredential object and is assign to the Credentials property of the Proxy object.
myProxy.Credentials = new NetworkCredential(userName, passWd);
myWebRequest.Proxy = myProxy;
Im not sure if I can set this to my SmtpClient client?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也有同样的问题。 SMTP 类没有代理属性,这使事情变得非常复杂。唯一想到的是使用 WebRequest 类并将邮件消息的每个属性作为单个字符串发送,然后等待服务器的响应(WebRequest 有一个代理属性)。但我还没有实施它。 :)
I'm having the same problem. The SMTP class doesn't have a proxy property, which makes things very complicated. The only thing that comes to mind is to use WebRequest class and to send every attribute of your mail message as a single string after which you wait for response by the server (WebRequest has a proxy property). But I haven't implemented it yet. :)