Home > BI, Code > Sending Email via Script Task in SSIS

Sending Email via Script Task in SSIS

The other day I was trying to figure out how to send an email via Script Task in SSIS. For some reason, the Send Email Task wasn’t working for me (still can’t figure out why). Anyway, here’s what I ended up with.

Works like a charm…


' Microsoft SQL Server Integration Services Script Task
' Write scripts using Microsoft Visual Basic
' The ScriptMain class is the entry point of the Script Task.
Imports System
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.Net.Mail
Imports System.Net

Public Class ScriptMain
    Public Sub Main()
      Dim myHtmlMessage As MailMessage
      Dim mySmtpClient As SmtpClient

      myHtmlMessage = New MailMessage(“email@somewhere.com”, “email@somewhereelse.com”, “Subject”, “Body”)
      mySmtpClient = New SmtpClient(“SMTP”)
      mySmtpClient.Credentials = CredentialCache.DefaultNetworkCredentials
      mySmtpClient.Send(myHtmlMessage)
      Dts.TaskResult = Dts.Results.Success
    End Sub
End Class

VN:F [1.9.1_1087]

Rating: 3.3/5 (3 votes cast)
VN:F [1.9.1_1087]
Rating: 0 (from 2 votes)
Sending Email via Script Task in SSIS, 3.3 out of 5 based on 3 ratings
Categories: BI, Code Tags: , , , , ,
  1. No comments yet.
  1. No trackbacks yet.