Solved

Console App:  Generate an email alert

Posted on 2007-04-09
3
174 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 70

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

839 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