I have an SSIS package which has a script task that sends emails. When the package is executed locally from Visual Studio, the email is successfully sent. However when I deploy the package through SSIS catalog, create and execute the job, the job runs successfully but I am not receiving any mail. Also when executing the package from under the Integration Services Catalog, it executes without any issues, still no email is sent. I have created a proxy account that uses credential, I guess there might be a missing link or setup error somewhere within these steps. Does anyone know how the Proxy account principals should be set? Or could at all be related to this? I have already tried these:
I have created a c# Console app, just for the email sending part, and when executing that on the same server, it sends the email without any issues.
Additional info to my problem:
- So initially I also had the Task Version issue (SSIS: script task (vs15) not work when deploy on sql server 2014), but after redeploying it with correct ISDeploymentWizard.exe, then this issue was solved.
- I’m also using Office365, but 2FA is turned off, and email was sent without any issues when executing the script task from Visual Studio (so when the package execution failed, it correctly went to Event Handlers, executed the script task, and mail was sent).
- I have proxy account configured to execute the SSIS package, and it works for other packages/steps.
- I have the following script behind the Script Task:
String SendMailFrom = Dts.Variables["$Project::Sender"].Value.ToString();
String SendMailFromPassword = Dts.Variables["$Project::SenderPassword"].GetSensitiveValue().ToString();
String SendMailTo = Dts.Variables["$Project::ToMail"].Value.ToString();
String SMTPServerName = Dts.Variables["$Project::SMTPServerName"].Value.ToString();
int SMTPServerPort = int.Parse(Dts.Variables["$Project::Port"].Value.ToString());
String PackageName = Dts.Variables["System::PackageName"].Value.ToString();
String ErrorDescription = Dts.Variables["System::ErrorDescription"].Value.ToString();
String ErrorCode = Dts.Variables["System::ErrorCode"].Value.ToString();
String SourceName = Dts.Variables["System::SourceName"].Value.ToString();
String Subject = PackageName + " Package Failed On " + DateTime.Now.ToString();
String Message = PackageName + " Package Failed On " + DateTime.Now.ToString();
try
MailMessage email = new MailMessage();
SmtpClient SmtpServer = new SmtpClient(SMTPServerName);
// START
email.From = new MailAddress(SendMailFrom);
email.To.Add(SendMailTo);
email.Subject = Subject;
email.Body = Message;
//END
SmtpServer.Port = SMTPServerPort;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Credentials = new System.Net.NetworkCredential(SendMailFrom, SendMailFromPassword);
SmtpServer.EnableSsl = true;
SmtpServer.Send(email);
}
catch (Exception ex)
{
}
Dts.TaskResult = (int)ScriptResults.Success;