C# System.Security.Cryptography.CryptographyException:句柄无效
我通过C#for发送邮件时遇到异常 asSystem.Security.Cryptography.CryptographyException:句柄无效。C# System.Security.Cryptography.CryptographyException:句柄无效,c#,asp.net,asp.net-mvc-3,sendmail,C#,Asp.net,Asp.net Mvc 3,Sendmail,我通过C#for发送邮件时遇到异常 asSystem.Security.Cryptography.CryptographyException:句柄无效。 MailMessage mail = new MailMessage(from,to); mail.To.Add(to); mail.From = new MailAddress(from, "", System.Text.Encoding.UTF8); mail.Su
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);
我不明白为什么会发生这种情况?请检查项目设置,并确保已检查NTLM身份验证:
ssl的端口不是
465
的可能重复项吗?这不是重复项。另一个问题在MailMessage
构造函数上有一个例外,但在这里它发生在SmtpClient
构造函数上。另外,另一个问题没有真正的答案。请尝试将您的邮件和SmtpClient包装在使用块中:使用(var mail=new MailMessage(…){…使用(var client=new SmtpClient(…){…}
我在另一个威胁中找到了解决方案。请查收
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);