DimPayeeLoad
 SCR Send Email With Alerts
  Properties
Property Value
Name SCR Send Email With Alerts
Description
Precedence Executables none
Contrained Executables none
BreakpointManager Microsoft.SqlServer.Dts.Runtime.BreakpointManager
Breakpoints System.Collections.ArrayList
CreationName Microsoft.SqlServer.Dts.Tasks.ScriptTask.ScriptTask, Microsoft.SqlServer.ScriptTask, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91
DebugMode False
DelayValidation False
Disable False
DisableEventHandlers False
EntryPoint Main
ExecutionDuration 0
ExecutionResult 0
ExecutionStatus 1
ExecutionValue
FailPackageOnFailure False
FailParentOnFailure False
ForcedExecutionValue 0
ForceExecutionResult -1
ForceExecutionValue False
ID {465efddb-d619-47fa-a0c3-75e6d0a37dbd}
IsDefaultLocaleID True
IsolationLevel 1048576
LocaleID English (United States)
LoggingMode 0
MaximumErrorCount 1
ReadOnlyVariables
ReadWriteVariables
ScriptingEngine Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine
ScriptLanguage Microsoft Visual Basic 2008
ScriptLoaded True
ScriptProjectName ST_b163c905ca3d45fd9133dcb4ab0f7f42
ScriptStorage Microsoft.SqlServer.VSTAHosting.VSTAScriptProjectStorage
SuspendRequired False
TransactionOption 1
Version 0
  Source Code
'/*
'Copyright  ?  2012  Pragmatic  Works  Inc.
'#####################################################################################################################
'LEGAL  NOTICE
'#####################################################################################################################
'THE  FOLLOWING  SOURCE  CODE  IS  PRODUCED  BY  PRAGMATIC  WORKS  INC.
'YOU  MUST  HAVE  A  VALID  LICENSE  OF  "BI  xPRESS"  (PRODUCT  OF  PRAGMATIC  WORKS)  TO  USE/MODIFY  THE  FOLLOWING  SOURCE  CODE.

'YOU  CAN  NOT  PUBLISH  ANY  PORTION  OF  THIS  SOURCE  CODE  WITHOUT  WRITTEN  PERMISSION  OF  PRAGMATIC  WORKS  INC.
'#####################################################################################################################  
'*/
Imports System
Imports System.Data
Imports System.Math
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()
    Action_SendMail()
      Dts.TaskResult = ScriptResults.Success
      End Sub
   Sub Action_SendMail()
       Dim SB_Body As New System.Text.StringBuilder()

       Dim isHTML As Boolean = ("HTML".ToUpperInvariant() = "HTML")

    'SB_Body.AppendLine("<H1>This  is  sample  email</H1><P>")
    'SB_Body.AppendLine("<H1>Hello  World!!!</H1><BR>")
    'SB_Body.AppendLine("<H2>Hello  World!!!</H2><BR>")
    'SB_Body.AppendLine("<H3>Hello  World!!!</H3><BR>")
    'SB_Body.AppendLine("<H4>Hello  World!!!</H4><BR>")


        SendMail(SnippetParameter("User::EmailTo""""") _
         , SnippetParameter("User::EmailFrom""""") _
         , "" _
         , "" _
         , "DimPayee.dtsx  -  Alert  Report" _
         , SnippetParameter("User::EmailBodyText""""") _
         , False _
         , SnippetParameter("User::SMTPServerName""""") _
         , Convert.ToInt32(SnippetParameter("User::SMTPPort""""")) _
         , Convert.ToBoolean(False) _
         , SnippetParameter("User::EmailUserName""""") _
         , SnippetParameter("User::EmailPassword""""") _
         , SnippetParameter("User::Domain""""") _
         , SnippetParameter("User::EmailAttachmentList""""") _
         , "High")


    'SendMail(SnippetParameter("User::EmailTo",  "",  "")  _
    '  ,  SnippetParameter("User::EmailFrom",  "",  "")  _
    '  ,  ""  _
    '  ,  ""  _
        '  ,  "DimStudentTermLoad.dtsx  -  Alert  Report"  _
    '  ,  SB_Body.ToString()  _
    '  ,  isHTML  _
    '  ,  SnippetParameter("User::SMTPServerName",  "",  "")  _
    '  ,  Convert.ToInt32(SnippetParameter("User::SMTPPort",  "",  ""))  _
    '  ,  Convert.ToBoolean(False)  _
    '  ,  SnippetParameter("User::EmailUserName",  "",  "")  _
    '  ,  SnippetParameter("User::EmailPassword",  "",  "")  _
    '  ,  SnippetParameter("User::Domain",  "",  "")  _
    '  ,  SnippetParameter("User::EmailAttachmentList",  "",  "")  _
    '  ,  "High")


  End Sub

   '  Example  :
   '  SendMail("someone@mycompany.com,
   '                    "support@dtsxchange.com;bob@dtsxchange.com",
   '                    "HTML  Test  Email!!!",
   '                    "<B>Hello</B>  How  are  you?",
   '                    True)
   Private Sub SendMail(ByVal sendTo As String, _
     ByVal sentFrom As String, _
    Optional ByVal cc As String = "", _
    Optional ByVal bcc As String = "", _
    Optional ByVal subject As String = "", _
    Optional ByVal body As String = "", _
    Optional ByVal isBodyHtml As Boolean = True, _
    Optional ByVal smtpServer As String = "localhost", _
    Optional ByVal smtpPort As Integer = 25, _
    Optional ByVal useSSL As Boolean = False, _
    Optional ByVal userName As String = "", _
    Optional ByVal password As String = "", _
    Optional ByVal domain As String = "", _
    Optional ByVal attachments As String = "", _
    Optional ByVal priority As String = "Normal")

     Using oMessage As New System.Net.Mail.MailMessage()
         oMessage.From = New System.Net.Mail.MailAddress(sentFrom)

         If String.IsNullOrEmpty(sendTo) = False Then
             oMessage.[To].Add(sendTo.Replace(";"","))
         End If

         If String.IsNullOrEmpty(cc) = False Then
             oMessage.CC.Add(cc.Replace(";"","))
         End If

         If String.IsNullOrEmpty(bcc) = False Then
             oMessage.Bcc.Add(bcc.Replace(";"","))
         End If

         If priority.ToUpperInvariant() = "HIGH" Then
             oMessage.Priority = System.Net.Mail.MailPriority.High
         ElseIf priority.ToUpperInvariant() = "LOW" Then
             oMessage.Priority = System.Net.Mail.MailPriority.Low
         Else
             oMessage.Priority = System.Net.Mail.MailPriority.Normal
         End If

         oMessage.Subject = subject
         oMessage.Body = body
         oMessage.IsBodyHtml = isBodyHtml

         '  Attachments
         If Not String.IsNullOrEmpty(attachments) Then
             Dim sFiles() As String = Split(attachments, "|")

             For Each sFile As String In sFiles
                 If Not String.IsNullOrEmpty(sFile) AndAlso System.IO.File.Exists(sFile) Then
                     oMessage.Attachments.Add(New System.Net.Mail.Attachment(sFile))
                 End If
             Next
         End If

         Dim mySmtpClient As New System.Net.Mail.SmtpClient(smtpServer, smtpPort)
         If String.IsNullOrEmpty(userName) Then
             mySmtpClient.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials
         Else
             mySmtpClient.Credentials = New System.Net.NetworkCredential(userName, password, domain)
         End If

         mySmtpClient.EnableSsl = useSSL

         Try
             mySmtpClient.Send(oMessage)
         Finally
             If oMessage IsNot Nothing AndAlso oMessage.Attachments IsNot Nothing AndAlso oMessage.Attachments.Count > 0 Then
                 For Each attachment As System.Net.Mail.Attachment In oMessage.Attachments
                     If attachment IsNot Nothing Then attachment.Dispose()
                 Next

                 oMessage.Attachments.Dispose()
             End If
         End Try
     End Using
   End Sub
#Region "Helper  functions"
    Private Property SnippetParameter(ByVal sVarName As StringByVal sConnName As StringByVal sConnPropName As StringAs Object
        Get
            Dim oRetVal As Object
            If String.IsNullOrEmpty(sConnName) = False Then
                Dim oCon As ConnectionManager
                oCon = Dts.Connections(sConnName)
                If String.IsNullOrEmpty(sConnPropName) Then
                    sConnPropName = "ConnectionString"
                ElseIf sConnPropName = "<object>" Then
                    Return oCon
                End If
                oRetVal = oCon.Properties(sConnPropName).GetValue(oCon)
            ElseIf String.IsNullOrEmpty(sVarName) = False Then
                oRetVal = ReadVariable(sVarName)
            Else
                oRetVal = Nothing
            End If

            Return oRetVal
        End Get
        Set(ByVal oValue As Object)
            If String.IsNullOrEmpty(sConnName) = False Then
                Dim oCon As ConnectionManager
                oCon = Dts.Connections(sConnName)
                If String.IsNullOrEmpty(sConnPropName) Then
                    sConnPropName = "ConnectionString"
                End If
                oCon.Properties(sConnPropName).SetValue(oCon, oValue)
            ElseIf String.IsNullOrEmpty(sVarName) = False Then
                WriteVariable(sVarName, oValue)
            End If
        End Set
    End Property
    Private Sub WriteVariable(ByVal varName As StringByVal varValue As Object)
        Try
           Dim vars As Variables = Nothing
           Dts.VariableDispenser.LockForWrite(varName)
           Dts.VariableDispenser.GetVariables(vars)
           Try
               vars(varName).Value = varValue
           Catch ex As Exception
               Throw ex
           Finally
               vars.Unlock()
           End Try
        Catch ex As Exception
            Throw ex
        End Try
    End Sub
    Private Function ReadVariable(ByVal varName As StringAs Object
        Dim result As Object
        Try
           If Not String.IsNullOrEmpty(varName) AndAlso Dts.VariableDispenser.Contains(varName) Then
               Dim vars As Variables = Nothing
               Dts.VariableDispenser.LockForRead(varName)
               Dts.VariableDispenser.GetVariables(vars)
               
               Try
                   result = vars(varName).Value
               Catch ex As Exception
                   Throw ex
               Finally
                   vars.Unlock()
               End Try
           Else
               result = Nothing
           End If
        Catch ex As Exception
            Throw ex
        End Try
        Return result
    End Function
#End Region
 End Class
  Variables
Name Value Description
Powered by BI Documenter