这是我的C#代码
try{
var fromAddress = new MailAddress("someone@gmail.com", "someone");
var toAddress = new MailAddress(EmailAddressTextBox.Text.Trim(), "Somename");
const string fromPassword = "password";
const string subject = "test1";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = "something"
})
{
message.IsBodyHtml = true;
smtp.Send(message);
}
}catch(Exception ex){}
它在smtp.send抛出了一个异常(消息) 异常消息:发送邮件失败。 内部异常消息:无法连接到远程服务器 内部异常消息:尝试以其访问权限禁止的方式访问套接字74.125.25.108:587 注意:在安装IIS之前,相同的代码工作正常