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.

1

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

2

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.

3

Now we will write the C# code.

4

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

5

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

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

//Step 2 : Provide Credentials..
string Username = "xyz123@gmail.com";
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.To.Add("abc@gmail.com");
message.Subject = "SSIS Script Task";
message.IsBodyHtml = true;
message.Body = "Hello World from MSBI";

//Step 5: Send Email..
client.Send(message);

			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.

6

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 : –

Advertisements

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:- https://www.youtube.com/watch?v=Lp7nSImO5vk Learn AngularJS Step by Step:- https://www.youtube.com/watch?v=0kmdjqgO9IY Learn Design Pattern in 8 hours:- https://www.youtube.com/watch?v=YDobmucohqk Learn C# and .NET in 60 days:- https://www.youtube.com/watch?v=yh2SrzCkNQA Learn MSBI in 32 hours:- https://www.youtube.com/watch?v=mGPJx3ocFgg Learn SharePoint Step by Step in 8 hours:- https://youtu.be/C2fW76SwJNU
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:

WordPress.com Logo

You are commenting using your WordPress.com 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