我的 Outlook 可以使用我的帐户设置发送电子邮件。但我无法从 C# 发送电子邮件。
这是我的帐户设置:
Microsoft exchange server: exch.server1.com;
User name: user1@server1.com;
Password: password1;
----- 安全选项卡 -----
Encrypt data between Microsoft Office Outlook and Microsoft Exchange - CHECKED;
Logon network security: Negotiate Authentication;
----- 连接选项卡 -----
Connect using my Local Area Network (LAN) - SELECTED;
Connect to Microsoft Exchange using HTTP - CHECKED;
----- 交换代理设置表格 -----
Use this email to connect to my proxy server fo Exchange: https://owa.server1.com
Connect using SSL only - CHECKED;
Only connect to proxy servers that have this principal name in their certificate: msstd:owa.server1.com;
Proxy authentication settings: NTLM Authentication;
这是我的 C# 代码:
var completeMessage = new MailMessage();
completeMessage.From = new MailAddress("ivanov@server1.com");
completeMessage.To.Add("ivanov@server1.com");
completeMessage.Subject = "test subject";
completeMessage.Body ="test body";
var client = new SmtpClient("exch.server1.com");
client.Credentials = new NetworkCredential("user1@server1.com", "password1");
client.Send(completeMessage);
出现以下异常:
The remote name could not be resolved: 'exch.server1.com'
这个网址“exch.server1.com”被我的办公室屏蔽了。请告诉我应该如何配置 SmtpClient 来发送电子邮件。