The script
task is a multi-purpose tool that we can use in a package to fill almost any
requirement that is not may be the task included with integrated services. The
Script task provides code to perform functions that are not available in the
built-in tasks and transformations that SQL Server Integration Services
provides. The Script task can also combine functions in one script instead of
using multiple tasks and transformations. You use the Script task for work that
must be done once in a package.
Example
Here I am going to use script task
to send the mail.
Double click on script task and
you will get script task editor. Here I am going to hard coded value but can
also pass the value through variables.
try
{
MailMessage
mail = new MailMessage();
SmtpClient
SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress(“XXXXXXXX@gmail.com");
mail.To.Add("XXXXXXXXXXX@gmail.com");
mail.Subject = "Test Mail";
mail.Body = "This is for testing SMTP mail from GMAIL using
SSIS Script task";
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("XXXXXXXXXX@gmail.com", "****(Your gmail password)***");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
MessageBox.Show("mail Send");
}
catch
(Exception ex)
{
MessageBox.Show(ex.ToString());
}
|
Save and close the script task
editor. Execute the package.
No comments:
Post a Comment
If you have any doubt, please let me know.