发信报"邮箱不可用,not local host xxx not a gateway"错误!!!!
我用System.Net.Mail的MailMessage、SmtpClient实现发信功能,代码如下:
public bool SendMail(string subject, string body, string mailFrom, string mailFromName, string mailTo, string mailToName, string mailDomain, string mailServerUserName, string mailServerPassWord)
{
try
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress(mailFrom, mailFromName);
msg.To.Add(new MailAddress(mailTo, mailToName));
msg.Subject = subject;
msg.Body = body;
msg.IsBodyHtml = true;
msg.BodyEncoding = Encoding.UTF8;
msg.Priority = MailPriority.High;
SmtpClient client = new SmtpClient();
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(mailServerUserName, mailServerPassWord, mailDomain); //帐号密码
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
client.Send(msg);
//老是在这里报错!!!!
return true;
}
catch (Exception ex) {
throw ex;
}
}
提示:邮箱不可用,not local host xxx not a gateway