Imports System
Imports System.Net
Imports System.Data
Imports System.Net.Mail
Imports System.IO
Imports System.Net.NetworkCredential
Imports Microsoft.SqlServer.Dts.Runtime
<System.AddIn.AddIn("ScriptMain", Version:="1.0", Publisher:="", Description:="")> _
<System.CLSCompliantAttribute(False)> _
Partial Public Class ScriptMain
Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
Enum ScriptResults
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
End Enum
Public Sub Main()
Dim oReader As StreamReader
Dim sTo As String
Dim sFrom As String = "EnterpriseAccountTeam@pdstech.com"
Dim sCC As String
Dim sMessage As String
Dim sSubject As String
Dim sJob_State As String
Dim sJob_Status As String
Dim sBranch As String
Dim sRec() As String
Dim sLine As String
Dim linefeed As String = Constants.vbCrLf
Try
'open file
oReader = New StreamReader("C:\Taleo\TCC\Prod\Export\Requisition\EmailFile.csv")
While oReader.Peek <> -1
sLine = oReader.ReadLine()
sRec = sLine.Split(Convert.ToChar("|"))
sTo = sRec(0)
sCC = sRec(1)
sSubject = "A new requisition has been assigned to you. Req No: " + sRec(2) + " Job title: " + sRec(3)
sMessage = "City: " + sRec(4) + linefeed + "State: " + sRec(5) + linefeed
sMessage += "Client: " + sRec(6) + linefeed + "Job state: " + sRec(7) + linefeed
sMessage += "Job status: " + sRec(8) + linefeed + "Branch: " + sRec(9)
'Send Mail
MailSend(sTo, sCC, sFrom, sSubject, sMessage)
End While
oReader.Close()
Catch ex As Exception
Dts.TaskResult = ScriptResults.Failure
End Try
Dts.TaskResult = ScriptResults.Success
End Sub
Public Sub MailSend(ByVal ToMail As String, ByVal ToCC As String, ByVal From As String, ByVal Subject As String, ByVal Message As String)
Dim smtpclient As New SmtpClient
Dim mailmessage As New MailMessage
Dim fromadd As New MailAddress(From)
smtpclient.Host = "10.1.0.10"
smtpclient.Port = 25
smtpclient.Credentials = CredentialCache.DefaultNetworkCredentials
mailmessage.From = fromadd
mailmessage.To.Add(ToMail)
mailmessage.CC.Add(ToCC)
mailmessage.Subject = CStr(Subject)
mailmessage.Body = CStr(Message)
smtpclient.Send(mailmessage)
End Sub
End Class