C# 发送邮件应用程序中的身份验证错误
我正在使用我的 CMail 服务器用 C# 开发一个简单的发送邮件应用程序:
MailMessage mail = new MailMessage("[email protected]", "[email protected]");
mail.Subject = "Sub";
mail.Body = "Hi!";
SmtpClient smtp = new SmtpClient("MyServer");
System.Net.NetworkCredential cred = new System.Net.NetworkCredential("user", "pass");
smtp.UseDefaultCredentials = false;
smtp.Credentials = cred;
smtp.Send(mail);
显然我省略了我的帐户信息,因此,此代码由于某种原因引发了身份验证异常。我首先认为代码是错误的,所以我将信息更改为我的 gmail 帐户,一切正常,唯一遇到问题的 SMTP 服务器是 CMail。 .NET和CMail的SMTP有问题吗?
感谢您的帮助和评论!
I'm developing a simple send mail app in C#, using my CMail Server:
MailMessage mail = new MailMessage("[email protected]", "[email protected]");
mail.Subject = "Sub";
mail.Body = "Hi!";
SmtpClient smtp = new SmtpClient("MyServer");
System.Net.NetworkCredential cred = new System.Net.NetworkCredential("user", "pass");
smtp.UseDefaultCredentials = false;
smtp.Credentials = cred;
smtp.Send(mail);
Obviously i ommited my account information, so, this code throws me an Authentication Exception for some reason. I first thought that the code was wrong, so i change the info to my gmail account and everything goes fine, with the only SMTP server that i having trouble is with the CMail. Is there a problem with .NET and CMail's SMTP ?
Thanks for the help and comments!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试添加:
Try adding:
如果您使用两步验证,则需要添加应用程序特定密码。
If you are using 2-step verification then you will need to add application specific password.
完整的工作样本
Full work sample