0

所以我写了这个程序给我的一群朋友发短信。当我尝试在工作中使用它时,它在家里工作正常,但它不起作用。我收到一条错误消息“发送邮件失败”。

我们在工作中使用拦截代理。我虽然/希望一切都能正常工作,显然不是。

那么我需要做什么,我从来没有编程通过代理连接/发送流量。

我正在使用 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 客户端?

谢谢

4

1 回答 1

1

我有同样的问题。SMTP 类没有代理属性,这使事情变得非常复杂。唯一想到的是使用 WebRequest 类并将邮件消息的每个属性作为单个字符串发送,然后等待服务器的响应(WebRequest 具有代理属性)。但我还没有实现它。:)

于 2011-01-13T18:17:30.613 回答