Email Task
Here's the basics of my map:
1. The map validates the existence of files on a remote FTP site.
2. Map then downloads the files to a local working directory on the network.
3. The map then spins through the file validating the date and account code. If it fails on the date it exits and is supposed to send an email. If it passes the date test, but fails on the account code, then it's supposed to exit and send an email.
When I ran this in test, it successfully sent the email when it failed on the date or account, but then continued on through the rest of the map. I need help on making the map stop if the tests in #3 fail and send the email to the accounting group and not continue on.
Thank you for any help.
If you want to conditionally send an email based off of the results of tasks that run before it, then I would probably make all the tasks scripting tasks. That way you can set a globabl variable in the tasks that check if the data fails your checks, and then look at that global variable before sending the email in the other script.
IF you want to end a map from a scripting task would would end it with the statement "Return False" rather than "Return True". So when you got to the script that sends the email, it would only do the email and the return false statement if one of those global variables were set by your data checking tasks/scripts.
If you want an exmaple of an email script you can search our knowledge base for "sample scripts" and there is a download that has a sample email script in it.
H
Chris –
Thanks for the reply. I did check out the sample script SendEmailAttachement.txt (which was the only one I saw in the sample script download) and used most of it to write the code as you suggested. However, I'm still having trouble with my date verification script and the subsequent email script.
This is my code for the Date and Account verification:
Dim JHIcsvArray() As String
Dim JHIcsvLine As String
Dim sr As New System.IO.StreamReader("\riskytoolsSQL_BackupsIBSSmartConnect_TestJHIWorkJHI_IBSUPLOAD.csv")
Dim dtDate As Date = System.DateTime.Today
Dim sysDate As String
Dim badAcct As String = "GPM-5/1*"
Dim strDate As String
Dim strAcct As String
While Not sr.EndOfStream
Do
JHIcsvLine = sr.ReadLine()
JHIcsvArray = Microsoft.VisualBasic.Split(JHIcsvLine, ",")
If Microsoft.VisualBasic.IsNumeric(JHIcsvLine.Substring(0, 8)) Then
strDate = System.Convert.ToDateTime(CStr(JHIcsvArray(1)))
sysDate = System.Convert.ToDateTime(CStr(dtDate))
strAcct = CStr(JHIcsvArray(2))
If strDate = sysDate Then
If strAcct.Substring(0, 8) <> badAcct Then
GBL_ACCTRESULT = True
Else
GBL_ACCTRESULT = False
sr.close()
Exit While
End If
Else
GBL_DATERESULT = False
sr.close()
Exit While
End If
End If
Loop Until JHIcsvArray Is Nothing
End While
sr.close()
And this is my code for the Email send part.
Dim emailSender As String = "SmartConnectAdmin@usrisk.com"
Dim emailReceiver As String = "sean.reynolds@usrisk.com"
Dim subject As String
Dim body As String
Dim hostServer As String = "HOSTSERVER"
Dim hostPort As Integer = 25
Try
Dim Message As New System.Net.Mail.MailMessage()
If GBL_ACCTRESULT = False Then
With Message
.To.Add(New System.Net.Mail.MailAddress(emailReceiver))
.From = New System.Net.Mail.MailAddress(emailSender)
.Subject = GBL_JHI_UPLOAD & "failed during upload process"
.Body = GBL_JHI_UPLOAD & "failed during the upload process to Dynamics GP because of bad account in the file. Please review and resolve."
.IsBodyHtml = True
End With
Else IF GBL_DATERESULT = False then
With Message
.To.Add(New System.Net.Mail.MailAddress(emailReceiver))
.From = New System.Net.Mail.MailAddress(emailSender)
.Subject = GBL_JHI_UPLOAD & "failed during upload process"
.Body = GBL_JHI_UPLOAD & "failed during the upload process to Dynamics GP because the date in the file is incorrect. Please review and resolve."
.IsBodyHtml = True
End With
End If
Dim SmtpClient As New System.Net.Mail.SmtpClient
SmtpClient.Host = hostServer
SmtpClient.Port = hostPort
SmtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network
SmtpClient.Send(Message)
Message.Dispose()
Catch ex As Exception
End Try
I believe I'm setting my globar variables correctly but my email seems to not be firing properly. I get a failure on the bad account but the email never sends. I'm sure this is something simple I'm missing, but I don't know what.
Thanks,
Sean