Hi in work we have a system that creates .tif documents and puts them into a folder if a reject happens for some reason. The folder is on our network eg. N:\Readsoft\Rejects
As it is at the moment people have to manually go in to this folder and check the rejects. Looking for a way to send an email each time a new document is created in the folder. Is This possible through SQL or VB.NET?
I had a stab at doing it through vb.net. I can retrieve the file names and the created date. So I could try and write some code for if the created date happen in the last x amount of hours. But wondering is there anyway I can get it to work when the file is created sort of like the way you can have a trigger on a database
Dim Directory As New IO.DirectoryInfo("c:\test")
Dim allFiles As IO.FileInfo() = Directory.GetFiles("*.*", IO.SearchOption.TopDirectoryOnly)
Dim rejects As New ArrayList(2)
For i = 0 To allFiles.Length - 1
MsgBox("There are " & allFiles.Length & " Emails In The Rejects Folder. An Email Has been sent to The Appropriate supervisor")
Dim SendTo(1) As String
Dim FileAttach(2) As String
Dim strSubject As String
Dim strMessage As String
SendTo(0) = "firstname.lastname@example.org"
SendTo(1) = "email@example.com"
FileAttach(0) = "c:\text.txt"
FileAttach(1) = "c:\Othertext.txt"
strSubject = "Email Subject"
strMessage = "Email Messge Text" 'The body encoding is set to HTML
SendEmail.SendEmailMessage("firstname.lastname@example.org", SendTo, strSubject, strMessage, FileAttach)
Public Sub SendEmailMessage(ByVal strFrom As String, ByVal strTo() _
As String, ByVal strSubject _
As String, ByVal strMessage _
As String, ByVal fileList() As String)
'This procedure takes string array parameters for multiple recipients and files
For Each item As String In strTo
'For each to address create a mail message
Dim MailMsg As New MailMessage(New MailAddress(strFrom.Trim()), New MailAddress(item))
'MailMsg.BodyEncoding = Encoding.Default
MailMsg.Subject = strSubject.Trim()
MailMsg.Body = strMessage.Trim() & vbCrLf
MailMsg.Priority = MailPriority.High
MailMsg.IsBodyHtml = True
'attach each file attachment
For Each strfile As String In fileList
If Not strfile = "" Then
Dim MsgAttach As New Attachment(strfile)
'Smtpclient to send the mail message
Dim SmtpMail As New SmtpClient
SmtpMail.Host = "10.35.50.64"
Catch ex As Exception