I am having a requirement where in I have used a send mail task in SSIS Package Post Execute Event Handler, in which I send a single email of consolidated errors. Now, based on client requirements, I need to enable or disable this send error email functionality. This flag (true/false)could be configured through package configuration. Can some one please point me in correct direction in implementing it?
2 Answers
Just add an expression to the precedence constraint just before the email module:
http://msdn.microsoft.com/en-us/library/ms140153.aspx
So if you have a user variable called sendmail, your precedence constraint could require that the expression @sendmail == true evaluates to true in order to continue to the sendmail task.
If you are using Package Configuration, then you simply change the value in your source (table, xml file, environment variable, registry key). If you want to set it at run time, you can also do so as an execution option. Assuming you had a variable, EnableMail, you can use a Set statement when you run the package to change the value of a variable.
dtexec.exe /file MyPackage /set \Package.Variables[User::EnableMail].Properties[Value];"True"
Now, if you have a mix of Configuration and you use the command line approach, there are differences between a 2005 and 2008 package in the order they are applied. See John Welch's article: Defining a Configuration Approach for Integration Services Packages
Either way you chose to assign the value to your Variable,, you can turn on off the Event Handler as a whole or just the mail sending portion. Simply assign an expression to the Disable property with your Variable.
I would also think about changing the name of my variable to match the positive/negative sense of the Disable property since a True for EnableMail would have a negated expression !@[User::EnableMail] but that's just semantics.