SMTP异常在System.Net.Mail.SmtpClient.Send(MailMessage消息)中发送mail.SMTP异常失败 我已附上以下代码,请查找代码: 使用System.net.mail
try
{
Load_LDAP_Details();
string subject = "Test SUbject";
string body = "This is a test body";
MailMessage mail = new MailMessage("abc@gmail.com", emailTo);
SmtpClient client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "smtp.server.com";
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
client.Send(mail);
client.EnableSsl = false;
lblEmail.Text = "sent";
client.Credentials = CredentialCache.DefaultNetworkCredentials;
}
catch (Exception ex) {
string message = string.Format("Time: {0}", DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt"));
message += string.Format("Message: {0}", ex.Message);
message += string.Format("StackTrace: {0}", ex.StackTrace);
message += string.Format("Source: {0}", ex.Source);
// message += string.Format("TargetSite: {0}", ex.TargetSite.ToString());
lblEmail.Text = message;
}