我试图从我们组织的Microsoft Exchange发送邮件,但收到错误消息:不允许客户向该服务器提交邮件。服务器的响应是:4.7.1:中继访问被拒绝
我的代码是:
private void button2_Click(object sender, EventArgs e)
{
string Username = "MyUsername";
string Password = "MyPassword ";
string SmtpServer = "OurSmtpServer";
string From = Username + "SmtpServer ";
System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient();
NetworkCredential basicCredential = new NetworkCredential(Username, Password, SmtpServer);
MailMessage message = new MailMessage();
System.Net.Mail.MailAddress fromAddress = new System.Net.Mail.MailAddress(From);
// setup up the host, increase the timeout to 5 minutes
smtpClient.Host = SmtpServer;
smtpClient.Port = 25;
smtpClient.UseDefaultCredentials = false;
//smtpClient.Credentials = basicCredential;
smtpClient.UseDefaultCredentials = true;
smtpClient.Timeout = (60 * 5 * 1000);
message.From = fromAddress;
message.Subject = " - " + DateTime.Now.Date.ToString().Split(' ')[0];
message.IsBodyHtml = true;
message.Body = " -88888888888888888888888888888 ";
message.To.Add("recipient@gmail.com");
smtpClient.Send(message);
}
我们通常在组织中使用Windows身份验证。这是问题的原因吗?如果可以,如何在我的代码中使用Windows身份验证?
在此先感谢您的帮助!