Solved

Console App:  Generate an email alert

Posted on 2007-04-09
3
167 Views
Last Modified: 2013-11-26
How would I go about writing a console app to check if a file exists on a network folder and then send an email alert....I have done this with winforms..but cant see to get started in a console environment.
0
Comment
Question by:Robb Hill
3 Comments
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 18877457
it is exactly the same thing
0
 
LVL 3

Expert Comment

by:JipFromParis
ID: 18877883
Assuming you are using Visual Studio, you should create a new "Console Application" project. The wizard will generate a single class and a single Main method. This method will be the entry point for your application. Arguments for the Main method is an array of strings. Each one will be populated with a single argument from the command line at runtime. As stated by emoreau, the programming techniques you will use should be the same. Copying/Pasting most of your WinForms application should do the job. One last note : you can use the many static methods from the System.Console class in order to write text to the command window. Other methods let you control almost any aspect of the command window. Hope it helps.
0
 
LVL 11

Author Comment

by:Robb Hill
ID: 18890503
Here was my solution less the app config settings



Imports System.Net.Mail
Imports System.io

Module Module1

    Sub Main()

        'Open a file for reading
        Dim FILENAME As String = "c:/Scheduler.log"
        Dim looptest As Boolean = True

        'Get a StreamReader class that can be used to read the file
        Dim objStreamReader As StreamReader
        objStreamReader = File.OpenText(FILENAME)

        'Now, read the entire file into a string
        Dim contents As String = objStreamReader.ReadToEnd()

        Dim a() As String = Split(contents, vbCrLf)
        Dim now As DateTime = DateTime.Now.ToShortDateString
        For i As Integer = 0 To a.Length - 1

            Dim strArray() As String = a(i).Split("-")
            strArray(1) = LTrim(strArray(1))
            Dim strDate() As String = strArray(1).Split(" ")

            If strDate(0) = now Then
                looptest = True
                Exit Sub
            Else
                looptest = False
            End If
        Next

        If looptest = False Then
            Dim mMailMessage As New MailMessage()
            'recipient e-mail address.
            mMailMessage.To.Add(New MailAddress(My.Settings.EmailAddress))
            ' Set the subject of the mail message
            mMailMessage.Subject = "ALERT"
            ' Set the body of the mail message
            mMailMessage.Body = "<HTML><BODY><B>ALERT! The system did not process the ADS_Blend Job</B></BODY></HTML>"
            ' Set the format of the mail message body as HTML
            mMailMessage.IsBodyHtml = True
            ' Set the priority of the mail message to normal
            mMailMessage.Priority = MailPriority.Normal

            ' Instantiate a new instance of SmtpClient
            Dim mSmtpClient As New SmtpClient()
            '    mSmtpClient.Host = "127.0.0.1"
            ' Send the mail message
            mSmtpClient.Send(mMailMessage)
        End If
    End Sub
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now