Create user(project) variables to have exchange server name, from email id, to email id and subject.
Get script task in evenhandler at OnError event. Select the below mentioned varibles in Read only variable option and apply the script
System::ErrorDescription
System::SourceName
System::PackageName
System::StartTime
$Project::ExchangeServerName
$Project::MailFrom
$Project::MailTo
$Project::Subject
//required namespaces
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Net.Mail;
using System.Text;
public void Main()
{
// TODO: Add your code here
string MessageTo = Dts.Variables["$Project::MailTo"].Value.ToString();
string MessageFrom = Dts.Variables["$Project::MailFrom"].Value.ToString();
DateTime StartTime = (DateTime)Dts.Variables["System::StartTime"].Value;
string packagename = Dts.Variables["System::PackageName"].Value.ToString();
string MessageSubject = packagename + " " + "Package Failed";
string sourcename = Dts.Variables["System::SourceName"].Value.ToString();
string MessageBody = Dts.Variables["System::ErrorDescription"].Value.ToString();
string smtpServer = Dts.Variables["$Project::ExchangeServerName"].Value.ToString();
SendMailMessage(MessageTo, MessageFrom, StartTime, packagename, MessageSubject, sourcename, MessageBody, true, smtpServer);
Dts.TaskResult = (int)ScriptResults.Success;
}
private void SendMailMessage(string SendTo, string From, DateTime Starttime, string Subject, string packagename, string sourcename, string Body, bool IsBodyHtml, string Server)
{
MailMessage htmlMessage;
SmtpClient mySmtpClient;
htmlMessage = new MailMessage(SendTo, From, Subject, Body);
StringBuilder mailstring = new StringBuilder();
mailstring.Append("<html><body>" + "<table border='1' width='100%'> <tr border=2 bgcolor='gray'><td border=2>Start Time</td><td>Package Name</td><td>Source Name</td><td>Error Description</td></tr><tr> <td border=2>"
+ Starttime + "</td><td>" +packagename + "</td><td>" + sourcename + "</td><td>" + Body + "</td></tr> </table></body></html>");
mySmtpClient = new SmtpClient(Server);
mySmtpClient.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
htmlMessage.IsBodyHtml = true;
htmlMessage.Body = mailstring.ToString();
mySmtpClient.Send(htmlMessage);
}
Get script task in evenhandler at OnError event. Select the below mentioned varibles in Read only variable option and apply the script
System::ErrorDescription
System::SourceName
System::PackageName
System::StartTime
$Project::ExchangeServerName
$Project::MailFrom
$Project::MailTo
$Project::Subject
//required namespaces
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Net.Mail;
using System.Text;
public void Main()
{
// TODO: Add your code here
string MessageTo = Dts.Variables["$Project::MailTo"].Value.ToString();
string MessageFrom = Dts.Variables["$Project::MailFrom"].Value.ToString();
DateTime StartTime = (DateTime)Dts.Variables["System::StartTime"].Value;
string packagename = Dts.Variables["System::PackageName"].Value.ToString();
string MessageSubject = packagename + " " + "Package Failed";
string sourcename = Dts.Variables["System::SourceName"].Value.ToString();
string MessageBody = Dts.Variables["System::ErrorDescription"].Value.ToString();
string smtpServer = Dts.Variables["$Project::ExchangeServerName"].Value.ToString();
SendMailMessage(MessageTo, MessageFrom, StartTime, packagename, MessageSubject, sourcename, MessageBody, true, smtpServer);
Dts.TaskResult = (int)ScriptResults.Success;
}
private void SendMailMessage(string SendTo, string From, DateTime Starttime, string Subject, string packagename, string sourcename, string Body, bool IsBodyHtml, string Server)
{
MailMessage htmlMessage;
SmtpClient mySmtpClient;
htmlMessage = new MailMessage(SendTo, From, Subject, Body);
StringBuilder mailstring = new StringBuilder();
mailstring.Append("<html><body>" + "<table border='1' width='100%'> <tr border=2 bgcolor='gray'><td border=2>Start Time</td><td>Package Name</td><td>Source Name</td><td>Error Description</td></tr><tr> <td border=2>"
+ Starttime + "</td><td>" +packagename + "</td><td>" + sourcename + "</td><td>" + Body + "</td></tr> </table></body></html>");
mySmtpClient = new SmtpClient(Server);
mySmtpClient.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
htmlMessage.IsBodyHtml = true;
htmlMessage.Body = mailstring.ToString();
mySmtpClient.Send(htmlMessage);
}