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 7005019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:16:32+00:00 2026-05-27T21:16:32+00:00

I am attempting to write this type of program as stated in the question.

  • 0

I am attempting to write this type of program as stated in the question. I have failed miserably and after no luck on msdn or google I am asking the intelligent minds of StackOverflow. My code is below for those interested in reading it.

I would like this program, on execution, to read a url to see if it is active and working properly. If it is not, and I get a bad response, an email is sent notifying someone that the website is down.

Im writing this is visual studio 2010 with C# and 3.5net. The program is reading the information (URLS and Email Addresses) from my Database from SQL Server 2008, the database will update with information based upon the sites reading per the HttpResponse (OK or NOTOK). If the website is NOTOK, then an email is sent. I am using a direct link library for the XOUlitities.Email.

The main issue is, it does not work and I have no clue why. It goes out and reads the website and comes back, but I receive no email.
My question is, is there an easier way for the email function? Can I just write the entire command inside the program without using the XOUtilities dll? I am basically looking for advice. When I run the .exe, there are no errors, but I believe the problem may lye within the email function. If anyone can shed any light on this issue, that would be great. Thank you in advance!

using System;
using System.Collections.Generic;
using System.Text;
using XOUtilities;
using System.Web;
using System.Net;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;

namespace WebsiteStatusCheck
{
class Program
{
    static string errorMsg;

    static void Main(string[] args)
    {
        string connectionString = ConfigurationManager.AppSettings["ConnectionString"];
        string tableName = ConfigurationManager.AppSettings["WebsiteListTableName"];
        string mailServer = ConfigurationManager.AppSettings["MailServer"];
        string replyToEmail = ConfigurationManager.AppSettings["ReplyToEmail"];

        string query = "SELECT * FROM " + tableName;
        SqlDataAdapter sDA = new SqlDataAdapter(query, connectionString);
        DataTable table = new DataTable();
        sDA.Fill(table);
        string[][] websites = new string[table.Rows.Count][];
        int i = 0;
        table.Columns.Add("isSiteAlive");
        table.Columns.Add("isDBAlive");
        foreach (DataRow row in table.Rows)
        {
            string[] temp = CheckURL(row["URL"].ToString());
            row["isSiteAlive"] = temp[0];
            row["isDBAlive"] = temp[1];
        }

        XOUtilities.Email email = new XOUtilities.Email();
        email.fromAddress = replyToEmail;
        email.server = mailServer;
        email.subject = "Website needs IMMEDIATE action";
        email.isHtml = true;
        email.body = @"The following website looks to be down:<br /><br /><table><tr><th>URL</th><th>Website</th><th>Database</th>";
        foreach(DataRow row in table.Rows)
        {
            if (row["isSiteAlive"].ToString().Trim() != "OK" || row["isDBAlive"].ToString().Trim() != "OK")
            {
                string tempbody = email.body;
                email.body += @"<tr><td><center>" + row["URL"].ToString() + @"</center></td><td><center>" + row["isSiteAlive"].ToString() + @"</center></td><td><center>" + row["isDBAlive"].ToString() + @"</center></td></tr>";
                email.toAddresses = row["EMAILS_CSV"].ToString().Split(new char[] { ',' });
                email.SendEmail();
                email.body = tempbody;
            }
        }
    }

    //string[0] = website value
    //string[1] = database value
    static string[] CheckURL(string url)
    {
        string[] ret = new string[2];
        try
        {
            WebClient client = new WebClient();
            Stream resp = client.OpenRead(url);
            StreamReader reader = new StreamReader(resp);
            string result = reader.ReadToEnd();
            ret[0] = "OK";
            ret[1] = result;
        }
        catch (WebException e)
        {
            errorMsg = e.Status.ToString();
            if (e.Status == WebExceptionStatus.ProtocolError)
            {
                errorMsg = ((HttpWebResponse)e.Response).StatusDescription;
            }
            ret[0] = errorMsg;
            ret[1] = "unreachable";
        }
        catch (Exception e)
        {
            errorMsg = e.Message;
            ret[0] = errorMsg;
            ret[1] = "unreachable";
        }
        return ret;
    }
}

}

  • 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-05-27T21:16:32+00:00Added an answer on May 27, 2026 at 9:16 pm

    I’ve never used XOUtilities, why not just use the libraries included in .NET? Just make sure your project has a reference to System.Net and then you can do something like this:

    System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
    message.To.Add("luckyperson@online.microsoft.com");
    message.Subject = "This is the Subject line";
    message.From = new System.Net.Mail.MailAddress("From@online.microsoft.com");
    message.Body = "This is the message body";
    System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("yoursmtphost");
    smtp.Send(message);
    

    Source of this snippet:
    http://social.msdn.microsoft.com/Forums/en/netfxnetcom/thread/a75533eb-131b-4ff3-a3b2-b6df87c25cc8

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

Sidebar

Related Questions

I have been attempting to write some routines to read RSS and ATOM feeds
I have an SSIS package I am developing. I am attempting to write data
In regards to my last question How would I write an interpreter for this
jQuery Version: 1.4.1 I am attempting to write a simple watermark type plugin and
I've been attempting to write a Lisp macro that would perfom the equivalent of
I am attempting to write an application that uses libCurl to post soap requests
I'm attempting to write a Python C extension that reads packed binary data (it
I am attempting to write a one-line Perl script that will toggle a line
I am attempting to write a component in C# to be consumed by classic
I am attempting to write a .NET component. The component will be dropped 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.