Solved

Console App:  Generate an email alert

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to LOAD up a .NET Framework website with data? 2 41
Help with retrieving partial value from a column using VB.NET 4 43
Host asp.net pages 5 25
C# Single Form 8 28
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

16 Experts available now in Live!

Get 1:1 Help Now