Smtp mail rejection exception

I am making an SMTP mail application with C # .Net. It works fine for Gmail settings, but I have to work with it to connect to VSNL. I get an exception: "Mail sending failure"

My settings seem perfect. What is the problem? Why am I getting an exception?

MailMessage mailMsg = new MailMessage(); MailAddress mailAddress = new MailAddress(" mail@vsnl.net "); 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(" mail@vsnl.net ", "password"); smtpClient.EnableSsl = true; smtpClient.UseDefaultCredentials = false; smtpClient.Credentials = credentials; smtpClient.Send(mailMsg); 

I get an exception after ...

System.IO.IOException: Unable to read data from transport connection: net_io_connection closed.

in System.Net.Mail.SmtpReplyReaderFactory.ProcessRead (byte buffer [], Int32 offset, Int32 read, logical readLine)
in System.Net.Mail.SmtpReplyReaderFactory.ReadLines (smtpReplyReader caller, Boolean oneLine)
in System.Net.Mail.SmtpReplyReaderFactory.ReadLine (call SmtpReplyReader)
on System.Net.Mail.SmtpConnection.GetConnection (host String, port Int32) in System.Net.Mail.SmtpTransport.GetConnection (host String, port Int32)
in System.Net.Mail.SmtpClient.GetConnection ()
in System.Net.Mail.SmtpClient.Send (MailMessage message)

+4
source share
7 answers

Check the InnerException for an exception, report why it failed.

+15
source

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

  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 determine what the problem is ...

+5
source

Make sure Kaspersky Anti-Virus blocks sending messages. In my case, McAfee Access security rules blocked sending emails, blocking blocks and reports.

+1
source

I used some, but I only check this if the error message fails:

 default value is false; 

but this cannot be changed to true;

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

The whole function should be surrounded by a try capture;

+1
source

Try removing smtpClient.EnableSsl = true; I'm not sure if vsnl supports SSL and the port number you are using

0
source

Without seeing your code, it is difficult to find the reason for the exception. The following are suggestions:

ServerHost VSNL smtp.vsnl.net

An exception:

 Unable to read data from the transport connection: net_io_connectionclosed 

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

0
source

Check if the machine is specifying an IPv6 address. In my case, using the machine name gave me the same error. Using the ip4 address, it worked (i.e. 10.0.0.4). I got rid of ipv6 and it started working.

Not the solution I was looking for, but given my limited understanding of ipv6, I did not know about other options.

0
source

Source: https://habr.com/ru/post/1333158/


All Articles