Click here to Skip to main content
15,312,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: Failure sending email.

What I have tried:

Good afternoon.
Hope you are all fine.

I just need some help regarding my project.

Everytime i try to send email using code i am receiving the error below.

" Failure sending email. --->
System.IO.IOException: Unable to read data from transportconnection: net_io_connectionclosed. at System.Net.mail.SmtpReplyReaderFactory.ProcessRead(Byte buffer, Int32 offset, Int32 read, Boolean readline)"

Note: I am using Office365.

Really appreciate if someone can give any idea how can i resolve this issue.
Thank you very much in advance.


Updated 19-Dec-21 2:23am

1 solution

Emails are a very notorious topic in software development, especially because they have different factors affecting the execution of your code—hostname, port, enable SSL, etc.

Since you've not shared the code, my guess is either you're not passing the enable SSL to your code, or the port is incorrect.

Please read the following articles that I wrote a while back that mention these challenges and (potentially) how to solve them:
Sending emails over .NET framework, and general problems – using C# code[^]
Universal SMTP Code to Send Emails in .NET Apps[^]
Leonel Masangcap 19-Dec-21 22:45pm
Hi Mr. Afzaal. Thank you very much for your reply. I will check the link you sent. Please check below code that i use for my project, please let me know if i did something wrong.

Dim Smtp_Server As New SmtpClient
Dim e_mail As New MailMessage()
Smtp_Server.UseDefaultCredentials = False
Smtp_Server.Credentials = New Net.NetworkCredential(usrEmailID, usrEmailpw)
Smtp_Server.Port = 587
Smtp_Server.EnableSsl = True
Smtp_Server.Host = ""

e_mail = New MailMessage()
e_mail.From = New MailAddress(usrEmailID)

e_mail.Subject = "Approval"
e_mail.IsBodyHtml = True
'attachment 1
Dim fileTXT As String = "c:\attach\" + invNo + ".pdf"
Dim data As Net.Mail.Attachment = New Net.Mail.Attachment(fileTXT)

'attachment 2
Dim fileTXT2 As String = "c:\attach\" + invNo + " - PL.pdf"
Dim data2 As Net.Mail.Attachment = New Net.Mail.Attachment(fileTXT2)
e_mail.Body = "INFORMATION" + "" + "" + "<font-family:arial>Invoice No.: " + "" & invNo & "" + "<font-family:arial> needs to review. " + "" + "" & _
"Please log in to the system to check what are the points that needs to modify." + "" + "" & _
"For any assistance, contact the system administrator." + "" + "" + "Thank you." + "" + "" + "" & _
"This is an auto-generated email – please do not reply."

Please note that the code above sometimes work, sometimes not.
Do you have any idea what's wrong with my code?

Again, thank you very much.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900