smtp 异常“发送邮件失败”

发布于 2024-10-08 18:58:20 字数 1583 浏览 6 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

青春有你 2024-10-15 18:58:20

检查异常的InnerException,应该告诉你失败的原因。

Check the InnerException of the exception, should tell you why it failed.

叹倦 2024-10-15 18:58:20

尝试将 Send 调用包装在 try catch 块中,以帮助识别潜在问题。
例如,

 try
 {
     smtpClient.Send(mailMsg);
 }
 catch (Exception ex)
 {
     Console.WriteLine(ex);   //Should print stacktrace + details of inner exception

     if (ex.InnerException != null)
     {
         Console.WriteLine("InnerException is: {0}",ex.InnerException);
     }
 }

此信息将有助于确定问题所在......

Try wrapping the Send call in a try catch block to help identify the underlying problem.
e.g.

 try
 {
     smtpClient.Send(mailMsg);
 }
 catch (Exception ex)
 {
     Console.WriteLine(ex);   //Should print stacktrace + details of inner exception

     if (ex.InnerException != null)
     {
         Console.WriteLine("InnerException is: {0}",ex.InnerException);
     }
 }

This information will help identify what the problem is...

不美如何 2024-10-15 18:58:20

确保您的防病毒软件阻止发送邮件。就我而言,迈克菲访问保护规则阻止发送邮件,取消勾选阻止和报告。

Make sure your Anti Virus is blocking sending mails. In my case McAfee Access protection Rules were blocking sending mails, untick blocks and reports.

遗心遗梦遗幸福 2024-10-15 18:58:20

我使用了一些,但如果发送邮件失败,我只检查这个:

default value is false;

但它不能更改为 true;

 smtpClient.Port = smtpServerPort;
 smtpClient.UseDefaultCredentials = false;
 smtpClient.Timeout = 100000;
 smtpClient.Credentials = new System.Net.NetworkCredential(mailerEmailAddress, mailerPassword);
 smtpClient.EnableSsl = EnableSsl;

所有函数都必须被 try catch 包围;

I used some but i am checking only this if send mail fails:

default value is false;

but it can't be change to true;

 smtpClient.Port = smtpServerPort;
 smtpClient.UseDefaultCredentials = false;
 smtpClient.Timeout = 100000;
 smtpClient.Credentials = new System.Net.NetworkCredential(mailerEmailAddress, mailerPassword);
 smtpClient.EnableSsl = EnableSsl;

All function must be surround by a try catch;

陌生 2024-10-15 18:58:20

尝试通过删除
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

绅刃 2024-10-15 18:58:20

如果不查看您的代码,很难找到异常的原因。以下是假设:

VSNL 的服务器主机是 smtp.vsnl.net

异常:

Unable to read data from the transport connection: net_io_connectionclosed

通常只有当用户名或密码不匹配<时才会发生此异常< /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:

Unable to read data from the transport connection: net_io_connectionclosed

Usually this exception occurs only when there is mismatch in username or password.

随心而道 2024-10-15 18:58:20

检查机器是否由 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文