Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8056217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:38:35+00:00 2026-06-05T08:38:35+00:00

I’m building a windows forms application that’s supposed to run on a remote/isolated machine

  • 0

I’m building a windows forms application that’s supposed to run on a remote/isolated machine and send error notifications by email to the admins. I’ve tried employing System.Net.Mail classes to achieve this but I’m running into a strange problem:

1. I get an error message:

System.IO.IOException: Unable to read data from the transport connection: 
An existing connection was forcibly closed by the remote host.--->
System.Net.Sockets.SocketException: An existing connection was forcibly closed by 
the remote host at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, 
Int32 size, SocketFlags socketFlags) at System.Net.Sockets.NetworkStream.
Read(Byte[] buffer, Int32 offset, Int32 size)

2. I tried sniffing the network activity to see what was going wrong. So here’s how it goes:

i) The DNS lookup for my SMTP server's hostname works
ii) My application connects to the SMTP server and sends "EHLO MY-HOSTNAME"
iii) SMTP server responds back with it's usual
iv) My application sends "AUTH login abcdxyz" and receives an acknowledgement packet

At this point, it seems that either the SMTP server doesn’t seem to request for the password or my machine shuts off the connection to the SMTP server before the SMTP server could request for a password.

I’ve tried using different SMTP ports and SMTP hosts. Also, I tried disabling my firewall and AV, but no luck. While connecting to my SMTP server using PuTTY and issuing the same sequence of commands as my application does (picked from the packet sniffer), everything works out fine and I’m able to send out the email.

Here’s the code that I’m using:

Imports System.Net
Imports System.Net.Mail

Public Function SendMail() As Boolean

     Dim smtpClient As New SmtpClient("smtp.myserver.com", 587) 'I tried using different hosts and ports
     smtpClient.UseDefaultCredentials = False
     smtpClient.Credentials = New NetworkCredential("username@domain.com", "password")
     smtpClient.EnableSsl = True 'Also tried setting this to false

     Dim mm As New MailMessage
     mm.From = New MailAddress("username@domain.com")
     mm.Subject = "Test Mail"
     mm.IsBodyHtml = True
     mm.Body = "<h1>This is a test email</h1>"
     mm.To.Add("someone@domain.com")

     Try
          smtpClient.Send(mm)
          MsgBox("SUCCESS!")
     Catch ex As Exception
          MsgBox(ex.InnerException.ToString)
     End Try

     mm.Dispose()
     smtpClient.Dispose()

     Return True

End Function

Any advice?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T08:38:36+00:00Added an answer on June 5, 2026 at 8:38 am

    In C# it works like this:

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
    
        private void btnTest_Click(object sender, RoutedEventArgs e)
        {
            MailAddress from = new MailAddress("Someone@domain.topleveldomain", "Name and stuff");
            MailAddress to = new MailAddress("Someone@domain.topleveldomain", "Name and stuff");
            List<MailAddress> cc = new List<MailAddress>();
            cc.Add(new MailAddress("Someone@domain.topleveldomain", "Name and stuff"));
            SendEmail("Want to test this damn thing", from, to, cc);
        }
    
        protected void SendEmail(string _subject, MailAddress _from, MailAddress _to, List<MailAddress> _cc, List<MailAddress> _bcc = null)
        {
            string Text = "";
            SmtpClient mailClient = new SmtpClient("Mailhost");
            MailMessage msgMail;
            Text = "Stuff";
            msgMail = new MailMessage();
            msgMail.From = _from;
            msgMail.To.Add(_to);
            foreach (MailAddress addr in _cc)
            {
                msgMail.CC.Add(addr);
            }
            if (_bcc != null)
            {
                foreach (MailAddress addr in _bcc)
                {
                    msgMail.Bcc.Add(addr);
                }
            }
            msgMail.Subject = _subject;
            msgMail.Body = Text;
            msgMail.IsBodyHtml = true;
            mailClient.Send(msgMail);
            msgMail.Dispose();
        }
    }
    

    Do not forget the using System.Net.Mail;

    I Think in VB it works like this to, here is the code, it might have some errors, I don’t often write in vb.net:

    Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        Dim _from As New MailAddress("Someone@domain.topleveldomain", "Name and stuff")
        Dim _to As New MailAddress("Someone@domain.topleveldomain", "Name and stuff")
        Dim cc As New List(Of MailAddress)
        cc.Add(New MailAddress("Someone@domain.topleveldomain", "Name and stuff"))
        SendEmail("Wan't to test this thing", _from, _to, cc)
    End Sub
    
    Protected Sub SendEmail(ByVal _subject As String, ByVal _from As MailAddress, ByVal _to As MailAddress, ByVal _cc As List(Of MailAddress), Optional ByVal _bcc As List(Of MailAddress) = Nothing)
    
        Dim Text As String = ""
        Dim mailClient As New SmtpClient("Mailhost")
        Dim msgMail As MailMessage
        Text = "Stuff"
        msgMail = New MailMessage()
        msgMail.From = _from
        msgMail.To.Add(_to)
        For Each addr As MailAddress In _cc
            msgMail.CC.Add(addr)
        Next
        If _bcc IsNot Nothing Then
            For Each addr As MailAddress In _bcc
                msgMail.Bcc.Add(addr)
            Next
        End If
        msgMail.Subject = _subject
        msgMail.Body = Text
        msgMail.IsBodyHtml = True
        mailClient.Send(msgMail)
        msgMail.Dispose()
    End Sub
    

    Do not forget to import System.Net.Mail

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words
We're building an app, our first using Rails 3, and we're having to build
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.