none
To send mail from SSIS package using script task component

    General discussion


  • To send mail from SSIS package using script task component
    Create and Set all following variable with respective values
    1)SMTPServer
    2)Subject
    3)From
    4)To
    5)Username(abc_xyz)
    6)Password(mailer domain password)
    7)Body
    Set readonly var. for script task as
    User:Tongue TiedMTPServer,User::Username,User:Stick out tongueassword,User::To,User::Body,User::From,User:Tongue Tiedubject
    Write following code inside script as

    Imports System

    Imports System.Data

    Imports System.Math

    Imports Microsoft.SqlServer.Dts.Runtime

    Imports System.Net.Mail

    Imports System.Net

    Public Class ScriptMain

    ' The execution engine calls this method when the task executes.

    ' To access the object model, use the Dts object. Connections, variables, events,

    ' and logging features are available as static members of the Dts class.

    ' Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.

    '

    ' To open Code and Text Editor Help, press F1.

    ' To open Object Browser, press Ctrl+Alt+J.

    Public Sub Main()

    '

    'MsgBox(Dts.Variables("Username").Value.ToString)

    Dim myHtmlMessage As MailMessage

    Dim mySmtpClient As SmtpClient

    'Dim vars As Variables

    Dim mailAuthentication As System.Net.NetworkCredential

    mailAuthentication = New System.Net.NetworkCredential(Dts.Variables("Username").Value.ToString(), Dts.Variables("Password").Value.ToString())

    myHtmlMessage = New MailMessage(Dts.Variables("From").Value.ToString(), Dts.Variables("To").Value.ToString(), Dts.Variables("Subject").Value.ToString(), Dts.Variables("Body").Value.ToString())

    mySmtpClient = New SmtpClient(Dts.Variables("SMTPServer").Value.ToString())

    'mySmtpClient.UseDefaultCredentials = False

    mySmtpClient.Credentials = mailAuthentication

    mySmtpClient.EnableSsl = True

    mySmtpClient.Send(myHtmlMessage)

    Dts.TaskResult = Dts.Results.Success

    Dts.TaskResult = Dts.Results.Success

    End Sub

    End Class


    Thursday, June 14, 2007 5:35 AM