在要求我在这个网站上搜索一些可能的解决方案之前。 我找到了Solution that I implemented in my code 但我有一个错误:当我发送带有我的代码的邮件(在localhost中)时,我获得“无效的处理程序”,但用户名和密码是正确的。有人可以帮助我吗?谢谢
这是cdoce
private SendGmail(){
try{
MailMessage mail = new MailMessage();
mail.From = new MailAddress("mymail@gmail.com", "Enquiry");
mail.To.Add(TextBox_mail.Text.ToString());
mail.IsBodyHtml = true;
mail.Subject = "Test";
mail.Body = "Some Text";
mail.Priority = MailPriority.High;
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
//smtp.UseDefaultCredentials = true;
smtp.Credentials = new System.Net.NetworkCredential("mymail@gmail.com", "password");
smtp.EnableSsl = true;
//smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Send(mail);
}
catch (Exception errore)
{
elenco_errori.Visible = true;
elenco_errori.InnerText = errore.Message;
}
}
答案 0 :(得分:0)
我解决了这个问题 在Application Start中,在global.asax中我添加了这段代码
public void Application_Start() {
System.Security.Cryptography.RSACryptoServiceProvider.UseMachineKeyStore = true;
System.Security.Cryptography.DSACryptoServiceProvider.UseMachineKeyStore = true;
}