ASp.net c# sql

June 4, 2008

SSIS: Send SMTP mail from Script task

Here i will show how to send SMTP email from a script task rather than the SMTP Mail 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(name@helpindotnet.blogspot.com,
“name@helpindotnet.blogspot.com”, “Subject”, “body”)
mySmtpClient = New SmtpClient(“192.168.3.75”)
mySmtpClient.Credentials = CredentialCache.DefaultNetworkCredentials
mySmtpClient.Send(myHtmlMessage)
Dts.TaskResult = Dts.Results.Success

Dts.TaskResult = Dts.Results.Success
End Sub
End Class

3 Comments »

  1. your site is very nice …
    this is very helpful and attractive.

    Comment by john — August 18, 2008 @ 6:31 pm

  2. i have one ssis script task which is sending mail when i run it from out side of sql server agent job .but it is not sending the mail when i run it fron sql server agent job and it is showing success.

    plz help me out

    thanks in advance

    Comment by mohammad izhar — April 5, 2011 @ 12:24 pm

    • Use try catch block around the script
      try
      {
      //send email script
      }
      catch(Exception ex)
      {
      Dts.TaskResult = Dts.Results.Failure
      }
      Record the ex.ToString() in some variable or write it on any file and check if the script throw error.

      Seems to be Permission issue.

      Comment by Admin — April 5, 2011 @ 12:56 pm


RSS feed for comments on this post. TrackBack URI

Leave a comment

Create a free website or blog at WordPress.com.