试图在我的 C# 应用程序中发送一些电子邮件。我在代理后面 - 这无疑是代码不起作用的原因。这是我到目前为止所拥有的:
应用程序配置:
<system.net>
<defaultProxy enabled="false">
<proxy proxyaddress="xxx.xxx.xxx.xxx"/>
</defaultProxy>
<mailSettings>
<smtp deliveryMethod="Network">
<network host="smtp.gmail.com" port="587"/>
</smtp>
</mailSettings>
</system.net>
代码:
var username = "...";
var password = "...";
var fromEmail = "...";
var toEmail = "...";
var body = "Test email body";
var subject = "Test Subject Email";
var client = new SmtpClient("smtp.gmail.com", 587)
{
Credentials = new NetworkCredential(username, password),
EnableSsl = true
};
try
{
client.Send(fromEmail, toEmail, subject, body);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
每次我得到 System.Net.WebException:无法解析远程名称:'smtp.gmail.com'
我在哪里/如何开始调试?