smtp 异常“发送邮件失败”
我正在使用 C#.Net 制作 SMTP 邮件应用程序。 Gmail 设置工作正常,但我必须将其用于与 VSNL 的连接。我遇到异常:“发送邮件失败”
我的设置看起来很完美。问题是什么?为什么我会收到异常?
MailMessage mailMsg = new MailMessage();
MailAddress mailAddress = new MailAddress("[email protected]");
mailMsg.To.Add(textboxsecondry.Text);
mailMsg.From = mailAddress;
// Subject and Body
mailMsg.Subject = "Testing mail..";
mailMsg.Body = "connection testing..";
SmtpClient smtpClient = new SmtpClient("smtp.vsnl.net", 25);
var credentials = new System.Net.NetworkCredential("[email protected]", "password");
smtpClient.EnableSsl = true;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = credentials;
smtpClient.Send(mailMsg);
我遇到以下异常...
System.IO.IOException:无法从传输连接读取数据:net_io_connectionclosures。
在 System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] 缓冲区,Int32 偏移量,Int32 读取,布尔 readLine)
在 System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader 调用者,布尔 oneLine)
在 System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader 调用者)
在 System.Net.Mail.SmtpConnection.GetConnection(字符串主机,Int32 端口) 在 System.Net.Mail.SmtpTransport.GetConnection(字符串主机,Int32 端口)
在 System.Net.Mail.SmtpClient.GetConnection()
在 System.Net.Mail.SmtpClient.Send(MailMessage 消息)
I am making an SMTP mail application with C#.Net. It is working ok for Gmail settings, but I have to work it for a connection to VSNL. I am getting an exception: "Failure sending mail"
My settings seem perfect. What is the problem? Why am I getting the exception?
MailMessage mailMsg = new MailMessage();
MailAddress mailAddress = new MailAddress("[email protected]");
mailMsg.To.Add(textboxsecondry.Text);
mailMsg.From = mailAddress;
// Subject and Body
mailMsg.Subject = "Testing mail..";
mailMsg.Body = "connection testing..";
SmtpClient smtpClient = new SmtpClient("smtp.vsnl.net", 25);
var credentials = new System.Net.NetworkCredential("[email protected]", "password");
smtpClient.EnableSsl = true;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = credentials;
smtpClient.Send(mailMsg);
I am getting an exception following...
System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed.
at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine)
at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine)
at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller)
at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpClient.GetConnection()
at System.Net.Mail.SmtpClient.Send(MailMessage message)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
检查异常的InnerException,应该告诉你失败的原因。
Check the InnerException of the exception, should tell you why it failed.
尝试将
Send
调用包装在 try catch 块中,以帮助识别潜在问题。例如,
此信息将有助于确定问题所在......
Try wrapping the
Send
call in a try catch block to help identify the underlying problem.e.g.
This information will help identify what the problem is...
确保您的防病毒软件阻止发送邮件。就我而言,迈克菲访问保护规则阻止发送邮件,取消勾选阻止和报告。
Make sure your Anti Virus is blocking sending mails. In my case McAfee Access protection Rules were blocking sending mails, untick blocks and reports.
我使用了一些,但如果发送邮件失败,我只检查这个:
但它不能更改为 true;
所有函数都必须被 try catch 包围;
I used some but i am checking only this if send mail fails:
but it can't be change to true;
All function must be surround by a try catch;
尝试通过删除
smtpClient.EnableSsl = true;
我不确定 vsnl 是否支持 SSL 以及您使用的端口号
Try by removing
smtpClient.EnableSsl = true;
I am not sure whether vsnl supports SSL and the port number you are using
如果不查看您的代码,很难找到异常的原因。以下是假设:
VSNL 的服务器主机是 smtp.vsnl.net
异常:
通常只有当用户名或密码不匹配<时才会发生此异常< /em>。
Without seeing your code, it is difficult to find the reason for exception. Following are assumptions:
The serverHost of VSNL is smtp.vsnl.net
Exception:
Usually this exception occurs only when there is mismatch in username or password.
检查机器是否由 IPv6 地址引用。就我而言,使用机器名称给了我同样的错误。使用 ip4 地址它确实可以工作(即 10.0.0.4)。我摆脱了 ipv6,它开始工作了。
这不是我正在寻找的解决方案,但鉴于我对 ipv6 的了解有限,我不知道还有其他选择。
Check to see if the machine is being referred to by an IPv6 address. In my case using machine name gave me the same error. Using the ip4 address it did work (i.e. 10.0.0.4). I got rid of ipv6 and it started to work.
Not the solution i was looking for but given my limited understanding of ipv6 I did not know of other choices.