0
votes

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?

2

2 Answers

3
votes

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
1
votes

Right click the task, and Set it Fail Package to true AND Forced value = Failure. (if its within a container, then you have to fail the container and then the container to fail package as well).