How to perform Script Task and send email using Script Task?

Script Tasks are used to send an email or do any web related tasks where customization is required. In Script Task for doing the customization we have to write C# code. It would be helpful for the MSBI training candidate if they have earlier worked with Visual Studio as writing C# code would require this tool to perform this lab easily.

So first of all we have to create a new package and inside that package we have to drag and drop the Script Task component from SSIS Toolbox.


After doing that we have to just double click on the Script Task component to configure it.


Now to write the C# code we have to click on option Edit Script and then a new Visual Studio window will open where we will write our C# code.


Now we will write the C# code.


This is how our Visual Studio window will look like where we have to write the code.


publicvoid Main()
// TODO: Add your code here

// Step 1 :  Configure SMTP..
SmtpClient client = newSmtpClient();
client.Host = "";
client.Port = 587;
client.EnableSsl = true;

//Step 2 : Provide Credentials..
string Username = "";
string Password = "xyz123";

NetworkCredential credential = newNetworkCredential(Username,Password);
client.Credentials = credential;

//Step 3: Configure from address..
MailAddressFromAddress = newMailAddress(Username, "John Doe");

//Step 4 : Create message to be sent..
MailMessage message = newMailMessage();
message.From = FromAddress;
message.Subject = "SSIS Script Task";
message.IsBodyHtml = true;
message.Body = "Hello World from MSBI";

//Step 5: Send Email..

			Dts.TaskResult = (int)ScriptResults.Success;

This is the C# code written step by step. No worries if candidate of MSBI traininghas never worked with C#,faculty helps to learn, understand and execute this lab.

After writing the code, we will close the window and click OK on our Script Task configuration dialog box.


After this done save the Script Task component and then execute the package.

In this way we can send email using Script Task component.

Also get to see following video on MSBI project series which start from the basic to start SSIS : –


About c# and .NET Interview questions

This blog is for developers who want to crack .NET and C# interviews. It has all tips and tricks needed to crack .NET interviews , C# interview , SQL Server interview , Java interview , WCF Interview , Silverlight interview , WPF interview , LINQ interview , Entity framework Interview. Do not forget to watch our Learn step by step video series. Learn MVC in 16 hours:- Learn AngularJS Step by Step:- Learn Design Pattern in 8 hours:- Learn C# and .NET in 60 days:- Learn MSBI in 32 hours:- Learn SharePoint Step by Step in 8 hours:-
This entry was posted in MSBI, Uncategorized and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s