views:

970

answers:

1

Is there any way to force a package to fail from a Send Mail Task? We have a package whose last step is to send a failure message using the Send Mail Task if certain criteria are met. Usually, we create another Script Task directly after the Mail Task which just fails the package using code:

Dts.TaskResult = Dts.Results.Failure

Is there a way to eliminate the Script Task and fail the package directly from the Send Mail Task?

+3  A: 

I had a similar scenario, instead of using the send mail task I decided to send email from the script task. That's the only way I found to combine sending an email and failing the package into one step.

Dim Message As MailMessage
Dim Smtp As SmtpClient

Message = New MailMessage("[email protected]", "[email protected]", "Packaged Failed", "Package Failed because...")

Smtp = New SmtpClient(Dts.Variables("EmailServer").Value.ToString())
Smtp.Credentials = CredentialCache.DefaultNetworkCredentials
Smtp.Send(Message)

Dts.TaskResult = Dts.Results.Failure
Mike Bennett
We've been using the method of sending email from script for about 2 weeks now so we can send HTML email from SSIS. In this case, we were just looking for a quick and easy way of sending email and failing the package with minimal code. I'm thinking the best way to do this now is to write a reusable assembly to handle this. Thanks for your help.
Mark Struzinski