I have an ssis package with an existing vb script task to send emails.
I am rewriting it in c#.
The vb version works, the c# version doesn't but it doesn't fail or error either, that I can see.
If I put a breakpoint in both, when I run the package to debug, it breaks in the vb script but not the c# script.
I have included the code for each below.
They are very similar so I am wondering if there is a task setting that controls this that I am overlooking.
Thanks in advance
The vb script is as follows.
...
Public Sub Main()
Dim htmlMessageFrom As String = Dts.Variables("SSISErrorEmailFrom").Value.ToString
Dim htmlMessageTo As String = Dts.Variables("SSISErrorEmailTo").Value.ToString
Dim htmlMessageSubject As String = Dts.Variables("SSISErrorEmailSubject").Value.ToString
Dim htmlMessageBody As String = Dts.Variables("SSISErrorEmailBody").Value.ToString
Dim SSISErrorTable As String = Dts.Variables("SSISErrorTable").Value.ToString
Dim smtpConnectionString As String = DirectCast(Dts.Connections("SMTP Connection").AcquireConnection(Dts.Transaction), String)
Dim smtpServer As String = "smtprelay.white01.babcockgroup.co.uk"
htmlMessageBody = htmlMessageBody.Replace("###subject###", htmlMessageSubject)
htmlMessageBody = htmlMessageBody.Replace("###SSISErrorTable###", SSISErrorTable)
SendMailMessage(
htmlMessageFrom, htmlMessageTo,
htmlMessageSubject, htmlMessageBody,
True, smtpServer)
Dts.TaskResult = ScriptResults.Success
End Sub
Private Sub SendMailMessage(
ByVal From As String, ByVal SendTo As String,
ByVal Subject As String, ByVal Body As String,
ByVal IsBodyHtml As Boolean, ByVal Server As String)
Dim htmlMessage As MailMessage
Dim mySmtpClient As SmtpClient
htmlMessage = New MailMessage(
From, SendTo, Subject, Body)
htmlMessage.IsBodyHtml = IsBodyHtml
mySmtpClient = New SmtpClient(Server)
mySmtpClient.Credentials = CredentialCache.DefaultNetworkCredentials
mySmtpClient.Send(htmlMessage)
End Sub
...
The c# scipt is as follows
...
public void Main()
{
sendEmail();
}
private void sendEmail()
{
var noBytes = new byte[0];
// TODO: Add your code here
try
{
string SSISErrorEmailTo = Dts.Variables["SSISErrorEmailTo"].Value.ToString();
string SSISErrorEmailFrom = Dts.Variables["SSISErrorEmailFrom"].Value.ToString();
string SSISErrorEmailSubject = Dts.Variables["SSISErrorSubject"].Value.ToString();
string SSISErrorEmailBody = Dts.Variables["SSISErrorEmailBody"].Value.ToString();
string SSISErrorTable = Dts.Variables["SSISErrorTable"].Value.ToString();
SSISErrorEmailBody.Replace("###subject###", SSISErrorEmailSubject);
SSISErrorEmailBody.Replace("###SSISErrorTable###", SSISErrorTable);
string SmtpServer = "smtprelay.white01.babcockgroup.co.uk";
MailMessage msg = new MailMessage(SSISErrorEmailFrom, SSISErrorEmailTo, SSISErrorEmailSubject, SSISErrorEmailBody);
msg.IsBodyHtml = true;
SmtpClient smtpClient = new SmtpClient(SmtpServer);
smtpClient.Credentials = CredentialCache.DefaultNetworkCredentials;
smtpClient.Send(msg);
Dts.TaskResult = (int)ScriptResults.Success;
Dts.Log("OnError script completed", -1, noBytes);
}
catch (Exception e)
{
Dts.TaskResult = (int)ScriptResults.Failure;
Dts.Log(e.InnerException.Message, -1, noBytes);
}
}
...