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

  • SEARCH
  • Home
  • 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 8788159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:05:51+00:00 2026-06-13T22:05:51+00:00

I just tried my hand at making a c# console program. The idea is

  • 0

I just tried my hand at making a c# console program. The idea is to make a small self contained application that’ll check against a database and send a list via email to a bunch of users, it’d be run automatically every morning for instance.

I have not yet gotten so far, just trying to get the basics down now first. By looking at tutorials online I’ve been able to connect to the database and display a list in the console. Sending the mail is less successful however.

If I include the code for sending mail inside the while loop, it’ll generate a bunch of individual mails so for some reason that works. But that’s not what I want. I want the list to run and compile a list that’ll become the message body. After that part of the program has run I want to send the mail. Problem is it doesn’t work, when I look at the server log, an SMTP session is opened but it terminates and says socket error sending response to DATA next line says Winsock error 10045 and the session is terminated.

Any idea why this happens? The thing that really makes no sense to me is that it works if run inside the while loop…

Here is the whole program as it currently stands:

namespace SendMails
{
class ConnectToMySQL
{
    [STAThread]
    static void Main(string[] args)
    {
        string connStr = createConnstr("192.168.111.1","database","login","passwd");

        MySqlConnection conn = null;
        MySqlDataReader reader = null;

        try
        {
            conn = new MySqlConnection(connStr);
            conn.Open();

            string stm = "SELECT id, name, surname FROM Kat WHERE Contact = 'Yes' AND Contactwhen <= '"+ DateTime.Today + "'";
            MySqlCommand cmd = new MySqlCommand(stm, conn);
            reader = cmd.ExecuteReader();

            //The actual output on the screen.
            while (reader.Read())
            {
               Console.WriteLine(reader.GetInt32(0) + ": " + reader.GetString(1) + " " + reader.GetString(2));                    
            }

        }
        catch (MySqlException ex)
        {
            Console.WriteLine("Error: {0}", ex.ToString());

        }
        finally
        {
            if (conn != null)
            {
                conn.Close();
            }
        }

        createMail("me@company.com", "info@company.com", "Test message", "Here is your test message.");

    }

    //This builds a mysql connection string
    public static string createConnstr(string server, string databaseName, string user, string passw)
    {
        //build connection string
        string connStr = "server=" + server + ";database=" + databaseName + ";uid=" + user + ";password=" + passw + ";";

        //return connection string
        return connStr;
    }

    //This sends an email
    static void createMail(string recipient, string from, string subject, string msg)
    {
        System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
        message.To.Add(recipient);
        message.Subject = subject;
        message.From = new System.Net.Mail.MailAddress(from);
        message.Body = msg;
        System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("192.168.111.1");
        try
        {
            Console.WriteLine("Sending mail...");
            smtp.Send(message);
            Console.WriteLine("Mail was sent successfully!");
        }
        catch (Exception ep)
        {
            Console.WriteLine("failed to send mail:");
            Console.WriteLine(ep.Message);
        }
    }

}

}

  • 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-13T22:05:52+00:00Added an answer on June 13, 2026 at 10:05 pm

    The problem is now solved. The solution was embarrassingly trivial.

    Merely needed to add smtp.Dispose(); after the line smtp.Send(message);

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

Sidebar

Related Questions

Just tried some small graphics application of mine on Windows 7, and I'm getting
I just tried to Make a solution on VS 2010 to practice consuming REST
I recently diverged from business application programming to trying my hand (just as a
I've never tried my hand at javascript but I'm just wanting to know if
I just tried to install git-flow, however, it does not seem to be integrated
I just tried to run my test app and I got this error: 2012-06-16
I just tried my first steps with grid . I would like to set
I just tried disassembling some shellcode using disasm and I found the following statement
I just tried the following code, but the result seems a little strange. It
I just tried to rebase a very old branch with a minor modification onto

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.