mailTo, subject, body,每个值都有取到,怎就报错呢?(之前一直正常的)报错提示: 捕捉到SmtpException "发送邮件失败"
先上代码 // 第二种异步方式发邮件方法
public static bool MailSendPrc(string mailTo, string subject, string body, out int sendDate, out int sendTime)
{
bool Bool = false;
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
//收件人
msg.To.Add(mailTo);
//msg.CC.Add(mailCC);
//发件人,发件人名
msg.From = new MailAddress("[email protected]","xxx");
//回复人,回复人名
//msg.ReplyTo = new MailAddress(reEmail, fromName);
msg.Subject = subject;//标题
msg.SubjectEncoding = System.Text.Encoding.UTF8;
msg.Body = body;//内容
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.IsBodyHtml = true;
msg.Priority = System.Net.Mail.MailPriority.High;
SmtpClient client = new SmtpClient("mail.xxxx.com.cn");
client.Port = 25;
client.ServicePoint.MaxIdleTime = 60;
client.UseDefaultCredentials = true;
client.Credentials = new System.Net.NetworkCredential("User1", "123456");
client.DeliveryMethod = SmtpDeliveryMethod.Network;
DateTime now = DateTime.Now;
sendDate = Convert.ToInt32(now.ToString("yyyyMMdd"));
sendTime = Convert.ToInt32(now.ToString("HHmmss"));
try
{
//异步发送邮件
client.SendCompleted += new SendCompletedEventHandler(sc_SendCompleted);
object userState = msg;
client.SendAsync(msg, userState);//走到这里后,直接跳到catch报错!正常情况应该Bool=true的
Bool = true;
}
catch (Exception)
{
Bool = false;
}
return Bool;
}谁能帮我解决一下啊!
先上代码 // 第二种异步方式发邮件方法
public static bool MailSendPrc(string mailTo, string subject, string body, out int sendDate, out int sendTime)
{
bool Bool = false;
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
//收件人
msg.To.Add(mailTo);
//msg.CC.Add(mailCC);
//发件人,发件人名
msg.From = new MailAddress("[email protected]","xxx");
//回复人,回复人名
//msg.ReplyTo = new MailAddress(reEmail, fromName);
msg.Subject = subject;//标题
msg.SubjectEncoding = System.Text.Encoding.UTF8;
msg.Body = body;//内容
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.IsBodyHtml = true;
msg.Priority = System.Net.Mail.MailPriority.High;
SmtpClient client = new SmtpClient("mail.xxxx.com.cn");
client.Port = 25;
client.ServicePoint.MaxIdleTime = 60;
client.UseDefaultCredentials = true;
client.Credentials = new System.Net.NetworkCredential("User1", "123456");
client.DeliveryMethod = SmtpDeliveryMethod.Network;
DateTime now = DateTime.Now;
sendDate = Convert.ToInt32(now.ToString("yyyyMMdd"));
sendTime = Convert.ToInt32(now.ToString("HHmmss"));
try
{
//异步发送邮件
client.SendCompleted += new SendCompletedEventHandler(sc_SendCompleted);
object userState = msg;
client.SendAsync(msg, userState);//走到这里后,直接跳到catch报错!正常情况应该Bool=true的
Bool = true;
}
catch (Exception)
{
Bool = false;
}
return Bool;
}谁能帮我解决一下啊!
没有 Async="true"
所以报错