我在使用C#发送邮件时遇到了异常
SmtpClient client = new SmtpClient()
出现 System.Security.Cryptography.CryptographicException: The handle is invalid. 错误。
MailMessage mail = new MailMessage(from,to);
mail.To.Add(to);
mail.From = new MailAddress(from, "", System.Text.Encoding.UTF8);
mail.Subject = "This is a test mail";
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Body = fr.message;
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = true;
mail.Priority = MailPriority.High;
SmtpClient client = new SmtpClient();
//Add the Creddentials- use your own email id and password
client.Credentials = new System.Net.NetworkCredential(from, Password);
client.Port = 587; // Gmail works on this port
client.Host = "smtp.gmail.com";
client.EnableSsl = true; //Gmail works on Server Secured Layer
client.Send(mail);
我不明白为什么会发生这种情况?
465
不是用于SSL吗? - V4Vendettausing (var mail = new MailMessage(...)){... using (var client = new SmtpClient(...)){ ...}}
- John Saunders