Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

Sending an HTML Mail Message with the Script Task

$
0
0

I really need help.

My task is to send a HTML Mail Message via SSIS and Script Task.

I am trying this VB.Code:

 Public Sub Main()
        Dim htmlMessageTo As String = _
     Dts.Variables("HtmlEmailTo").Value.ToString
        Dim htmlMessageFrom As String = _
          Dts.Variables("HtmlEmailFrom").Value.ToString
        Dim htmlMessageSubject As String = _
          Dts.Variables("User::HtmlEmailSubject").Value.ToString
        Dim htmlMessageBody As String = _
          Dts.Variables("HtmlEmailBody").Value.ToString
        Dim smtpConnectionString As String = _
   DirectCast(Dts.Connections("HtmlEmailServer").AcquireConnection(Dts.Transaction), String)
        Dim smtpServer As String = _
          smtpConnectionString.Split(New Char() {"="c, ";"c})(1)



        SendMailMessage( _
            htmlMessageTo, htmlMessageFrom, _
            htmlMessageSubject, htmlMessageBody, _
            True, smtpServer)

        Dts.TaskResult = ScriptResults.Success

    End Sub

    Private Sub SendMailMessage( _
        ByVal SendTo As String, ByVal From As String, _
        ByVal Subject As String, ByVal Body As String, _
        ByVal IsBodyHtml As Boolean, ByVal Server As String)

        Dim htmlMessage As MailMessage
        Dim mySmtpClient As SmtpClient

        htmlMessage = New MailMessage( _
          SendTo, From, Subject, Body)
        htmlMessage.IsBodyHtml = IsBodyHtml



        mySmtpClient = New SmtpClient(Server)
        mySmtpClient.Credentials = CredentialCache.DefaultNetworkCredentials
        mySmtpClient.Send(htmlMessage)

    End Sub

but it doesn't work out.

The Variables are ReadOnlyVariables in the Script Task Editor.

I am always getting a runtime error

at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams) at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()

Please help !!!

Or just give me another soultion for my task. Please explain as simple as possible because I am new to SSIS.

Thanks in advance


Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>