C# 使用Gmail SMTP发送邮件失败

C# 使用Gmail SMTP发送邮件失败,c#,email,smtp,C#,Email,Smtp,我之所以在这里发帖,是因为我已经尝试了很多次通过c#(Visual Studio 2015)中的程序发送电子邮件,但我不能。例外情况是: System.dll中发生类型为“System.Net.Mail.SmtpException”的未处理异常 其他信息:发送邮件失败 我的代码如下: MailMessage msg = new MailMessage(from.Text, to.Text, subject.Text, body.Text); SmtpClient smclient = new

我之所以在这里发帖,是因为我已经尝试了很多次通过c#(Visual Studio 2015)中的程序发送电子邮件,但我不能。例外情况是:

System.dll中发生类型为“System.Net.Mail.SmtpException”的未处理异常 其他信息:发送邮件失败

我的代码如下:

MailMessage msg = new MailMessage(from.Text, to.Text, subject.Text, body.Text); 
SmtpClient smclient = new SmtpClient("smpt.gmail.com", 587); //465
smclient.Credentials = new System.Net.NetworkCredential("haroncv@gmail.com", "(password)");
smclient.EnableSsl = true;
smclient.Send(msg);
MessageBox.Show("Mail Sent");
其中:

from.text = "haroncv@gmail.com"
to.text = "haroncv@gmail.com"
subject.text = "Sending email"
body.text = "hello world, how are you"

我想你遇到的问题与我在这里遇到的问题相同。希望这有帮助。

当您进入代码时,错误具体发生在哪里?您能否共享堆栈跟踪?错误发生在:smpt.Send(msg);请检查一下,在您的smpt.gmail.com引用中,smpt而不是smtp是您的帖子中的一个打字错误吗?可能是因为您正在本地运行,或者是因为凭据错误。只是猜测